Workbook_BeforeClose Event

captculver

Board Regular
Joined
Dec 8, 2008
Messages
60
I have a project summary workbook that several people will access to update project status. When they try to close the workbook, I would like a message box to come up asking if they have updated the revision date. I have the following code in place, which brings up the message box, but regardless of the response entered the workbook closes. How do I cancel the workbook closure and return to the "Summary" worksheet if the response is "No" to the msgbox question?

Thanks for your help, CC

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim msg As String
Dim myTitle As String
Dim Response As String


msg = "For the projects you updated, did you change the revision date?"
myTitle = "PROJECT UPDATES"
Response = MsgBox(msg, vbExclamation + vbYesNo, myTitle)
If Response = vbNo Then
Sheets("Summary").Activate
Else
Exit Sub
End If

End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim msg As String
Dim myTitle As String
Dim Response As String
msg = "For the projects you updated, did you change the revision date?"
myTitle = "PROJECT UPDATES"
Response = MsgBox(msg, vbExclamation + vbYesNo, myTitle)
If Response = vbNo Then
    Cancel = True
    Sheets("Summary").Activate
End If
End Sub
 
Upvote 0
Try:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)    Dim msg As String
    Dim myTitle As String
    Dim Response As String


    msg = "For the projects you updated, did you change the revision date?"
    myTitle = "PROJECT UPDATES"
    Response = MsgBox(msg, vbExclamation + vbYesNo, myTitle)
    If Response = vbNo Then
        Cancel = True
        Sheets("Summary").Activate
    End If


End Sub

Dom
 
Upvote 0

Forum statistics

Threads
1,203,605
Messages
6,056,239
Members
444,852
Latest member
MJaspering

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top