Workbook_beforeclose +msgbox

  • Thread starter Thread starter Phoenix
  • Start date Start date
P

Phoenix

Thanks, Sharad, that helped a bit. Now Excel doesn't ask to save, bu
the message box still pops up one more time after pressing "no".

Phoeni
 
Insert a Module in the project. In the module just put following single line
to define a Public Variable 'norepeat'
-x-
Public norepeat As Integer
-x-

(Public variables must be defined at module level.)

Then change the beforeclose code as under:-

-x-
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim UserResponse As String

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

End Sub
-x-

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

Back
Top