Is it possible to add buttons to a custom toolbar from a macro?

Thanks,

Flint

Re: Adding buttons from a macro by Shauna

Shauna
Mon Feb 12 03:17:48 CST 2007

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


"Flint" <qwerty@ctv_nospam.es> wrote in message
news:84455D50-C1A0-485B-B9EC-B59175C455D9@microsoft.com...
> Is it possible to add buttons to a custom toolbar from a macro?
>
> Thanks,
>
> Flint