Workbook_beforeclose +msgbox

P

Phoenix

Hi!

I'm using this code in "ThisWorkbook":

Private Sub Workbook_beforeclose(Cancel As Boolean)
Dim UserResponse As String

UserResponse = MsgBox("Remember to HIDE and PROTECT. Do you want t
save before closing?", vbYesNoCancel)
If UserResponse = vbYes Then
Me.Save
End If
If UserResponse = vbNo Then
Me.Close
End If
If UserResponse = vbCancel Then
Cancel = True
End If

End Sub


The problem is when i press "no". Then the box pops up twice....an
after pressing "no" twice excel asks again if i want to save. Why d
this happens?

Phoeni
 
S

Sharad Naik

Instead of just 'Me.Close' use:-

Me.Close SaveChanges:=False

Also you may not like to save again if already saved.

So Instead of just 'Me.Save', use:-

If Not Me.Saved Then Me.Save

Sharad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top