ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Workbook_beforeclose +msgbox (https://www.excelbanter.com/excel-programming/313963-workbook_beforeclose-msgbox.html)

Phoenix

Workbook_beforeclose +msgbox
 

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

--
Phoeni
-----------------------------------------------------------------------
Phoenix's Profile: http://www.excelforum.com/member.php...nfo&userid=292
View this thread: http://www.excelforum.com/showthread.php?threadid=27038


Sharad Naik

Workbook_beforeclose +msgbox
 
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


"Phoenix" wrote in message
...

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

Phoenix


--
Phoenix
------------------------------------------------------------------------
Phoenix's Profile:
http://www.excelforum.com/member.php...fo&userid=2921
View this thread: http://www.excelforum.com/showthread...hreadid=270386





All times are GMT +1. The time now is 06:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com