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 2007

Tip: Looking for answers? Try searching our database.

Adding buttons from a macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Flint - 12 Feb 2007 08:16 GMT
Is it possible to add buttons to a custom toolbar from a macro?

Thanks,

Flint
Shauna Kelly - 12 Feb 2007 09:17 GMT
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

> Is it possible to add buttons to a custom toolbar from a macro?
>
> Thanks,
>
> Flint
 
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.