INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

VBA Visual Basic for Applications (Microsoft) FAQ

Office / VBA General

What are the CommandBar Control Names and IDs in Word & Excel by Loomah
Posted: 16 Jan 04

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

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!!

Back to VBA Visual Basic for Applications (Microsoft) FAQ Index
Back to VBA Visual Basic for Applications (Microsoft) Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close