I want to use VBA to add a macro to a toolbar in Word.
When I record a macro doing this manually, it just leaves this VBA-command:
CommandBars("Menu Bar").Controls.Add Type:=msoControlButton, Before:= 19
without any reference to the name of the selected macro.
How do I write the VBA-code to add a given macro (say Normal.Modul1.Mymacro)
to the Standard toolbar (or a custom one) and editing the name property to
Mymacro?
Thanks, Frank
Hi Frank,
>I want to use VBA to add a macro to a toolbar in Word.
>
[quoted text clipped - 9 lines]
> to the Standard toolbar (or a custom one) and editing the name property to
> Mymacro?
After adding it, you set the OnAction property of the button to the name of
the macro, like this
Dim oButton as CommandBarControl
Set oButton = CommandBars("Menu Bar").Controls.Add( _
Type:=msoControlButton, Before:= 19)
oButton.OnAction = "Modul1.Mymacro"

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Frank - 24 Feb 2005 23:43 GMT
Thanks for the solution.
However, I could not find any usable "text only" property on the command bar
control to make it visible.
How is this done in VBA?
Frank
> Hi Frank,
>
[quoted text clipped - 19 lines]
> Type:=msoControlButton, Before:= 19)
> oButton.OnAction = "Modul1.Mymacro"
Jonathan West - 25 Feb 2005 00:44 GMT
> Thanks for the solution.
>
[quoted text clipped - 3 lines]
>
> How is this done in VBA?
You set the Caption property to determine the caption text, and you set the
Style property to msoButtonCaption in order to have the button display as a
text button.
Dim oButton as CommandBarControl
Set oButton = CommandBars("Menu Bar").Controls.Add( _
Type:=msoControlButton, Before:= 19)
oButton.OnAction = "Modul1.Mymacro"
oButton.Caption = "My macro"
oButton.Style = msoButtonCaption

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup