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 / January 2007

Tip: Looking for answers? Try searching our database.

add a button in the standard toolbal

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kanwal - 22 Jan 2007 03:48 GMT
Hello,

I am trying to add a button in the standard toolbar and load it using
startup folder templates.

I have found this code - which is adding a button (Version number) but i
dont understand how can i add my custom button in it ?

Also, i want the code to check if the button already exist - if yes, dont
create again.

CustomizationContext = NormalTemplate
CommandBars("Standard").Controls.Add Type:=msoControlButton, ID:=2522,
Before:=4

Can anyone help ?

Thanks

Kanwal
Lene Fredborg - 22 Jan 2007 10:13 GMT
Hopefully, use can use the code below as the starting point.

In VBA, a button is a CommandBarControl that can have different styles
(msoButtonStyle). The style determines how the button appears in the user
interface. For example, “msoButtonCaption” results in a button that has no
icon but only a written name. If you want to use an icon, you can copy the
icon from another control using CopyFace and apply it to your control using
PasteFace.

I have added some comments in the code that may help you. You will find
information on most of the propteries in the Help. If you want an underlined
character (keyboard accelerator) in the button name so that the command can
be executed by pressing Alt+[underlined character], change the Caption - add
an “&” in front of the letter to be underlined (e.g. “&MyControl”).

   Dim oBar As CommandBar
   Dim oControl As CommandBarControl
   Dim bControlExists As Boolean
   Dim strMyControl As String
   
   'Define name of control - replace by the name you want
   strMyControl = "MyControl"
   
   'Define which template to change - may not be Normal.dot
   CustomizationContext = NormalTemplate
   
   Set oBar = CommandBars("Standard")
   'Check whether control exists
   For Each oControl In oBar.Controls
       If oControl.Caption = strMyControl Then
           bControlExists = True
           Exit For
       End If
   Next oControl
   
   'If control was not found, add it
   If bControlExists = False Then
       'In the next code line, change Before to the desired position
       'If left out, the control will be added at the end of the toolbar
       Set oControl = oBar.Controls.Add(Type:=msoControlButton, Before:=1)
       'Apply desired caption, functionality, etc.
       With oControl
           'Define the style of the button - member of msoButtonStyle
           'See the Object Browser (F2) for possible values
           .Style = msoButtonCaption
           .Caption = strMyControl
           'Replace the value below by a value that identifies
           'the macro that your button is to execute
           .OnAction = "MyModule.MyMacro"
           'Other possible properties:
           'Tag, Parameter, DescriptionText, ShortcutText, TooltipText
       End With
   End If

   Set oBar = Nothing
   Set oControl = Nothing

Signature

Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word

> Hello,
>
[quoted text clipped - 16 lines]
>
> Kanwal
 
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.