Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What are the CommandBar Control Names and IDs in Word & Excel

Office / VBA General

What are the CommandBar Control Names and IDs in Word & Excel

by  Loomah  Posted    (Edited  )
This FAQ as been developed as a result of a question in the Office forum regarding obtaining button face pictures, icons. The code was never intended for that purpose but it was a useful side effect!! What these pieces of code give are lists of commandbars, command button names and their IDs (and some pics) for Excel and Word

The code below should be run while you have an empty worksheet activated for each routine

Code:
Sub ListXLPopups()
   Dim cbCtl As CommandBarControl
   Dim cbBar As CommandBar
   Dim i As Integer

   On Error Resume Next
   Application.ScreenUpdating = False
   Cells(1, 1).Value = "CommandBar"
   Cells(1, 2).Value = "Control"
   Cells(1, 3).Value = "FaceID"
   Cells(1, 4).Value = "ID"
   i = 2
   For Each cbBar In CommandBars
      Application.StatusBar = "Processing Bar " & cbBar.Name
      If cbBar.Type = msoBarTypePopup Then
         Cells(i, 1).Value = cbBar.Name
         i = i + 1
         For Each cbCtl In cbBar.Controls
            Cells(i, 2).Value = cbCtl.Caption
            cbCtl.CopyFace
            If Err.Number = 0 Then
               ActiveSheet.Paste Cells(i, 3)
               Cells(i, 3).Value = cbCtl.FaceId
            End If
            Cells(i, 4).Value = cbCtl.ID
            Err.Clear
            i = i + 1
         Next cbCtl
      End If
   Next cbBar
   Range("A:B").EntireColumn.AutoFit
   Application.StatusBar = False
End Sub


Sub ListWRDPopups()
'this is my attempt to recreate the above procedure for Word
   Dim cbCtl As CommandBarControl
   Dim cbBar As CommandBar
   Dim i As Integer
   Dim wdApp As New Word.Application

   On Error Resume Next
   Application.ScreenUpdating = False
   Cells(1, 1).Value = "CommandBar"
   Cells(1, 2).Value = "Control"
   Cells(1, 3).Value = "FaceID"
   Cells(1, 4).Value = "ID"
   i = 2
   For Each cbBar In wdApp.CommandBars
      Application.StatusBar = "Processing Bar " & cbBar.Name
      'Add the following condition if required
      'If cbBar.Type = msoBarTypePopup Then
         Cells(i, 1).Value = cbBar.Name
         i = i + 1
         For Each cbCtl In cbBar.Controls
            Cells(i, 2).Value = cbCtl.Caption
            cbCtl.CopyFace
            If Err.Number = 0 Then
               ActiveSheet.Paste Cells(i, 3)
               Cells(i, 3).Value = cbCtl.FaceId
            End If
            Cells(i, 4).Value = cbCtl.ID
            Err.Clear
            i = i + 1
         Next cbCtl
      'End If
   Next cbBar
   wdApp.Quit
   Range("A:B").EntireColumn.AutoFit
   Application.StatusBar = False
End Sub

This is a work in progress as I am considering highlighting possible usage of the IDs etc. maybe in another FAQ.
Comments welcome!!
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top