The following script works fine whenever I close my workbook. However, I have a button on my command bar to "Exit Excel" and if I click that button and then click cancel, part of the code, specifically, the line to delete myToolBar is already executed. Consequently, if I click cancel after clicking on the "Exit Excel" button, my toolbar is gone. Is there a way to detect if "Cancel" is clicked so that either none of the code in this script is run OR myToolBar is automatically recreated?
[VBA]
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.CommandBars(myToolBar).Delete
Call RestoreToolbars
End Sub
[/VBA]