Custom Toolbar

J

Josh O.

I've been reading about adding custom commands/buttons/macros to a toolbar
and need some help.

I would like to be able to have a macro check for a certain button on the
"Standard" tool bar, and if it's not present, then add the button, and assign
a macro.

Your help would be greatly appreciated. I have tried it using the
techniques I have seen, but obviously I am missing something.
 
R

Ron de Bruin

Hi Josh

Delete the button first in the code before you add it with code.
Something like this


Sub MenuBar_Item()
Call MenuBar_Item_Delete

With Application.CommandBars("Standard")
With .Controls.Add(Type:=msoControlButton, temporary:=True, before:=1)
.Style = msoButtonCaption
.Caption = "&Hi"
.TooltipText = "Hi again"
.OnAction = ThisWorkbook.Name & "!TestMacro1"
.Tag = "MyTag1"
End With

End With
End Sub

Sub MenuBar_Item_Delete()
On Error Resume Next
Application.CommandBars.FindControl(Tag:="MyTag1").Delete
On Error GoTo 0
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top