Adding buttons from a macro

S

Shauna Kelly

Hi Flint

Sure. Try something like this:

Sub CreateToolbarButtons()

Dim oBar As Office.CommandBar
Dim oButton As Office.CommandBarButton


'MUST tell Word where to save the changes
'Change this to suit your needs
Application.CustomizationContext = ActiveDocument.AttachedTemplate

'Add the toolbar
Set oBar = CommandBars.Add("MyToolbar")

With oBar
'Set the toolbar to be visible
.Visible = True

'Add a button
Set oButton = .Controls.Add(Type:=msoControlButton)

'Set properties for the button
With oButton
.Style = msoButtonIconAndCaption
.Caption = "My button caption"
.FaceId = 352
.OnAction = "MyMacro"
.TooltipText = "Click here to run MyMacro"
End With
End With

'You'll now need to save the template in which you
'created the menu bar and buttons

End Sub


Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

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