Adding Controls in a toolbar?

K

Kevin B

This will add a new control to the worksheet menu bar:

Sub NewControl()

Dim cmd As CommandBarButton

Set cmd = Application.CommandBars("Worksheet Menu Bar"). _
Controls.Add

With cmd
.BeginGroup = True
.Caption = "My New &Button"
.Style = msoButtonCaption
.BeginGroup = True
.OnAction = "Insert Macro Name Here"
End With

OnExit:

Set cmd = Nothing

End Sub
 
K

Kevin B

I was a bit too fast with the mouse click.

The .Caption statement is the name of your command with the ampersand
indicating which letter is the hot-key. And the OnAction statement is the
name of the macro you want to execute when the user clicks the button.
 

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