Search code examples
excelvbams-officecommandbar

How to get VBE CommandBars Control ID number list


The following code is taken from this link.

https://forum.ozgrid.com/forum/index.php?thread/32040-minimize-vba-window-with-code/

Sub Macro1()

    Dim cbcTemp As CommandBarControl

    On Error Resume Next

    Set cbcTemp = Application.VBE.CommandBars.FindControl(ID:=752)
    If Not cbcTemp Is Nothing Then
        cbcTemp.Execute
    End If

    On Error GoTo 0

End Sub

The Control ID is 752 in given example above.

I need to understand what every ID number is doing.

Does anybody know how to get VBE CommandBars Control ID number list?


Solution

  • This will loop through all command bars and their controls. The names / descriptions of the controls aren't great...

        Dim cbtemp As CommandBar
        Dim cbctemp As CommandBarControl
        
        For Each cbtemp In Application.VBE.CommandBars
            Debug.Print "command bar:", cbtemp.ID, cbtemp.Name
            For Each cbctemp In cbtemp.Controls
                Debug.Print cbctemp.ID, cbctemp.Caption, cbctemp.TooltipText
            Next
        Next
    

    You may need to output this onto a sheet as mine exceeds the immediate windows display.

        Dim cbtemp As CommandBar
        Dim cbctemp As CommandBarControl
        
        Dim i As Long
        i = 1
        For Each cbtemp In Application.VBE.CommandBars
            Cells(i, 1).Value = cbtemp.ID
            Cells(i, 2).Value = cbtemp.Name
            For Each cbctemp In cbtemp.Controls
                i = i + 1
                Cells(i, 3).Value = cbctemp.ID
                Cells(i, 4).Value = cbctemp.Caption
                Cells(i, 5).Value = cbctemp.TooltipText
            Next
            i = i + 1
        Next