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).
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).