Custom TBoolbar Deleted BeforeClose, How do I Reinstate on Cancel?

TemiU

Board Regular
Joined
Dec 11, 2014
Messages
52
I created a custom toolbar for my Excel application which gets created (through VBA code) when the workbook opens and deleted in the BeforeClose event of the Workbook. This is working fine.

I ran into the following issue: If a user clicks close and the workbook has not been saved, he/she is then prompted to save, don't save, or cancel. If cancel is chosen, the workbook is not closed. However, the BeforeClose event fires before the prompt to save, so the toolbar gets deleted. Is there any event that I can harness to recreate the toolbar, should the user cancel the save?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Let's assume that the procedure to delete the custom toolbar is called "DeleteMenu", try...

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Workbook_BeforeClose(Cancel [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Boolean[/COLOR])
    [COLOR=darkblue]Dim[/COLOR] Msg [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] Ans [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]
    [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] Me.Saved [COLOR=darkblue]Then[/COLOR]
        Msg = "Do you want to save the changes you made to "
        Msg = Msg & Me.Name & "?"
        Ans = MsgBox(Msg, vbQuestion + vbYesNoCancel, "Save Changes?")
        [COLOR=darkblue]Select[/COLOR] [COLOR=darkblue]Case[/COLOR] Ans
            [COLOR=darkblue]Case[/COLOR] vbYes
                Me.Save
            [COLOR=darkblue]Case[/COLOR] vbNo
                Me.Saved = [COLOR=darkblue]True[/COLOR]
            [COLOR=darkblue]Case[/COLOR] vbCancel
                Cancel = [COLOR=darkblue]True[/COLOR]
                [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR]
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Select[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    DeleteMenu
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,221,525
Messages
6,160,327
Members
451,637
Latest member
hvp2262

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