How to set a button in a toolbar to delete the whole toolbar without having to call other procedure

bernatbosch

Board Regular
Joined
Dec 12, 2015
Messages
66
I have a custom toolbar which I have added into the Excel's built-in formatting toolbar. The custom toolbar is meant to have several buttons, the first of which should allow the removal of the whole custom toolbar from the formatting toolbar if the user clicks on it.

In order to remove the toolbar, I have created an specific procedure called "REMOVE_ProjectFilesToolbar", and therefore this is the code that I assign to the .OnAction statement when the toolbar is created.

This is the code I use to create the toolbar and add that first button into it:


ToolbarName = "Project Files"
Set NewPopupMenu = Application.CommandBars("Formatting").Controls.Add(Type:=msoControlPopup)
NewPopupMenu.Caption = ToolbarName

' add a first button to allow users manually removing the toolbar
With NewPopupMenu
Set NewRemoveButton = NewPopupMenu.Controls.Add(Type:=msoControlButton)
On Error Resume Next
With NewRemoveButton
.Style = msoButtonIconAndCaption
.Caption = "Remove This Menu!"
.OnAction = "REMOVE_ProjectFilesToolbar" '(the title of the next Sub)
.TooltipText = "Use this button to remove this toolbar from your Formatting toolbar."
End With
On Error GoTo 0
End With

Here go my questions:



1) Is it possible to assign directly (to the button) an order to auto-delete the whole toolbar?


I mean, something like… .OnAction = me.parent.delete


(my goal here would be avoid having to have a separate procedure to remove the toolbar)


2) If not, then is it possible at least to develop a procedure that can identify the toolbar to be deleted without having to use the toolbar's name (caption) as a reference?


(my goal again is to get a 'clever code' which could be able to identify what toolbar the user is trying to delete by the time the user calls the action).
 

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.

Forum statistics

Threads
1,215,487
Messages
6,125,086
Members
449,206
Latest member
ralemanygarcia

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