Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

How to use VBA to add a macro to a toolbar in Word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frank - 24 Feb 2005 15:45 GMT
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
Jonathan West - 24 Feb 2005 16:03 GMT
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


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.