Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts

    CommandBars.FindControl ID List (VBA Word 2003)

    Hi,

    I need to write a macro that will automatically action a tool bar button so the user doesnt have to press it. The problem is, the button in question has been put onto the Word Standard toolbar as part of a third party software package.

    Is the anyway I can list all the CommandBars Control ID numbers, of the standard tool bar?

    Ive recorded a macro when pressing this particular button but unfortunately it didnt pick it up.

    Many thanks.
    Lee

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

    Re: CommandBars.FindControl ID List (VBA Word 2003)

    You can run this macro in a blank document:

    Sub ListIDs()
    Dim cbr As CommandBar
    Dim i As Integer
    Set cbr = CommandBars("Standard")
    For i = 1 To cbr.Controls.Count
    Selection.TypeText i & vbTab & cbr.Controls(i).ID & _
    vbTab & cbr.Controls(i).Caption & vbCr
    Next i
    End Sub

    The macro writes a line into the document for each toolbar control on the Standard toolbar, with the following info:
    - The index of the control (1, 2, ...)
    - Its ID.
    - Its Caption

  3. #3
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: CommandBars.FindControl ID List (VBA Word 2003)

    Hi Hans,

    Thats perfect. Thanks for your help.

    The only thing is the list provided showed a few items with the same ID number, in particular '1'.

    Im interested in particular in actioning the toolbar button BarsAndStripes. Ive inlcuded 1 into my toggle macro, but nothing happens. The toggle macro is below for ease of reference and Ive inlcuded the toolbar list, also for ease of reference.

    Sub ToggleItems(f As Boolean)
    On Error Resume Next
    ' Toolbar items
    CommandBars.FindControl(ID:=1).Enabled = t
    CommandBars.FindControl(ID:=1).Enabled = t
    End Sub

    Is it the case that because it is listed as '1', that the true ID number isnt being shown?

    Regards.
    Lee
    Attached Files Attached Files

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

    Re: CommandBars.FindControl ID List (VBA Word 2003)

    Custom commandbar controls always have an ID of 1. They don't have a "hidden" other ID. You'll have to identify them by their Caption property.

  5. #5
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: CommandBars.FindControl ID List (VBA Word 2003)

    Ok.

    Many thanks for your help, its much appreciated.

    Regards.
    Lee

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: CommandBars.FindControl ID List (VBA Word 2003)

    Note that your macro takes a boolean <code>f</code> parameter but uses <code>t</code> in the actual body of the routine, which I presume is a mistake.
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: CommandBars.FindControl ID List (VBA Word 2003)

    Hi Rory,

    Thanks for the note. It should have been a t - Doh !!

    Regards.
    Lee

Posting Permissions

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