ThisWorkBook BeforeClose Event
Carlos I use the Auto_Close() event to get rid of a toolbar.
as I think this code is always run before the workbook shuts down
Sub Auto_Close()
On Error Resume Next
CommandBars("Name").Delete '<<<<< change name to name of toolbar
With ActiveWorkbook
.RunAutoMacros xlAutoClose
.Close
End With
End Sub
It's not quite what you want but you vould adapt this
Dim msg, Style, Title, Response
msg = "Close the model" ' Define message."
Style = vbYesNoCancel + vbExclamation + vbDefaultButton2 ' Define buttons.
Title = "Selection" ' Define title.
'Display message.
Response = MsgBox(msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
Call Auto_Close
End If
If Response=VbNo then
Exit sub
End if
If Response=VbCancel then
Exit Sub
End if
"Carlos Lozano" wrote in message
...
Hi,
My application creates a toolbar on Opening (this works fine) and I am
trying to delete it when the workbook is closed. I am calling the Toolbar's
delete method on the BeforeClose event of the ThisWorkBook Object.
The current behavior is below:
1) If the document was not modified, it works perfectly
2) If the document was modified, it prompts to save changes and if "yes"
or "No" are selected works fine. The BeforeClose event is executed as
expected.
2) If the document was modified, and "cancel" is selected the BeforeClose
event is executed. I wasn't expecting this as the workbook was not closed.
So, It deletes the toolbar and the workbook remains open (with no toolbar
which is a problem). The beforeClose event is executed before the message is
shown.
How can I know what was selected on the "Do you want to save..." message?
to choose the right action.
Thank you,
Carlos Lozano
CAX IT Services
|