How can I capture the ThisWorkbook.BeforeClose result?

turbotoan

Board Regular
Joined
Feb 25, 2002
Messages
62
I need to interrogate the result of the prompt that displays after the BeforeClose event runs.

This is the message box that displays currently:
Microsoft Excel
Do you want to save the changes you made to 'FILENAME'?
YES NO CANCEL

If the user clicks CANCEL, I need to make sure some code I have does NOT execute.

Any suggestions? Is there a "CLOSING" event that I am not aware of that I can use to capture the result of this message?
Thank you. :rolleyes:
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Thanks much for your help!
This worked super!

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim strMsg As String
Dim bytResponse As Byte

'Prompt to save any other changes
Call Closing_Save_Database_Changes

'Handle the standard prompt on the workbook itself.
If Not Me.Saved Then
strMsg = "Do you want to save the changes you made to "
strMsg = strMsg & Me.name & "?"
bytResponse = MsgBox(strMsg, vbQuestion + vbYesNoCancel)
Select Case bytResponse
Case vbYes
'Only unlock if we know it is closing.
Call Unlock_Version
Me.Save
Case vbNo
'Only unlock if we know it is closing.
Call Unlock_Version
Me.Saved = True
Case vbCancel
'Do not unlock the spreadsheet.
Cancel = True
Exit Sub
End Select
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,893
Members
449,194
Latest member
JayEggleton

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