Results 1 to 9 of 9
  1. #1
    Star Lounger
    Join Date
    Dec 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Identifying Buttons on a Toolbar (Word 2000)

    I have the following line of code in a macro (based on advise from a previous thread on this board):

    With Application.CommandBars("MyToolbar").Controls(7)

    Is there another way to identify the button than .Controls(7), so that I can distribute the macro to others who may not have 6 other buttons on a toolbar? Or to make sure that 2 years sown the road I (or someone else with a variation of my macro) doesn't add another button making the physical button #8, while the code remains pointing to #7...

    Thanks,
    Shabtai

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Identifying Buttons on a Toolbar (Word 2000)

    You can also use the name/caption of a commandbar button, as displayed when you right-click a button in Customize mode. Note that this includes the ampersand & that indicates the underlined letter in the caption (if present). For example, for a button with caption Test:

    With Application.CommandBars("MyToolbar").Controls("&Te st")

  3. #3
    Star Lounger
    Join Date
    Dec 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identifying Buttons on a Toolbar (Word 2000)

    It turns out that just changing:
    With Application.CommandBars("MyToolbar").Controls(7)
    to
    With Application.CommandBars("MyToolbar").Controls("MyB utton")
    gives: Runtime error 5: Invalid Procedure call or Argument.

    I needed: With Application.CommandBars("MyToolbar").Controls("Nor mal.Para_key_Macros.TogButtons")
    Go figure.

    Saturn

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Identifying Buttons on a Toolbar (Word 2000)

    Apparently, "Normal.Para_key_Macros.TogButtons" is the name of that button...

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Identifying Buttons on a Toolbar (Word 2000)

    You also can use other means of identifying a button, such as a "tag" value that you add to it when the button is created. If you search in help under FindControl, it should give an example of how that can be used. Just in case someone changes the button caption...

  6. #6
    Star Lounger
    Join Date
    Dec 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identifying Buttons on a Toolbar (Word 2000)

    Sorry.

    I looked at the help, and, being a planet of little brain, I just don't see how to create a button with a tag, let alone how to add a tag later. Could you provide examples? And an example of later identifying the button using a tag?

    I thank you.

  7. #7
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Identifying Buttons on a Toolbar (Word 2000)

    A very brief example for you.

    <font face="Georgia">
    Application.CommandBars.Add Name:="Test"
    Application.CommandBars("Test").Controls.Add Type:=msoControlButton
    Application.CommandBars("Test").Controls(1).Captio n = "Test Button"
    Application.CommandBars("Test").Controls(1).Tag = "TestButtonTag"
    Application.CommandBars("Test").Controls(1).OnActi on = "MyMacro"
    </font face=georgia>

    or even better...

    <font face="Georgia">
    Dim ctlNew As CommandBarControl
    Set ctlNew = Application.CommandBars("test").Controls.Add
    ctlNew.Tag = "TestButtonTag"</font face=georgia>
    etc.

    StuartR

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Identifying Buttons on a Toolbar (Word 2000)

    I recommend Stuart's "even better" approach. You could name the button after one of your moons!

  9. #9
    Star Lounger
    Join Date
    Dec 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identifying Buttons on a Toolbar (Word 2000)

    (Edited by HansV to activate URL - see <!help=19>Help 19<!/help>)

    18 at last count (the big ones anyway). They do me proud!
    http://mars.sgi.com/worlds/CyberMarz/Satur...aturnMoons.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •