• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA - close wb

vasim

Member
Hi,


I am using this vba, its working fine till the time save option button is clicked but when the users click on the Red cross button, save alert is displayed, I click NO the wb closes without saving, I click cancel, thats fine (I want this option), I click YES ("Thats were the problem is) the message box populates and again the save alert. How can I stop this.


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

If Range("A1") <> Range("b1") Then

MsgBox "Not same"

Cancel = True

End If


End Sub
 
Hello Indian,


I assume you are using the code on "ThisWorkbook".


Your code looks like, if A1<>B1, then if you press CTRL+S (to perform save operation) then a message box will be popped up and you will have the option to hit OK only to end the subroutine.


Where your "YES" option is coming up that populates the message box and save alert as well? I have a disconnect here in understanding.


Could you upload a sample workbook and explain it further bit more clearly to me?


Kaushik
 
Stupid I'm (not able to explain properly).....let me simple it....

if A1 <> B1 then the workbook shouldn't save at all (not even when I click the red cross button at top).
 
Hi Indian,


As per my understanding.. Your code is doing the same..

shouldn't save at all (not even when I click the red cross button at top).

By the way.. if you want to save the sheet.. try this one instead..

[pre]
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If [a1] <> [b1] Then
If MsgBox("Not same" & Chr(10) & "Do you still want to save!!", 4) = 7 Then Cancel = True
End If
End Sub
[/pre]
 
Back
Top