Code to list command bar controls (1 Viewer)

Cronk

Registered User.
Local time
Tomorrow, 00:43
Joined
Jul 4, 2013
Messages
2,770
This is not a question but some code which some others might find useful.

I have been commissioned to upgrade an MDB database, including installing a customized ribbon menu. While I could see the old existing commandbar structure in 'Add-ins', I also needed to know the call back functions.

The following code shows this information. Apologies if this is reinventing an existing wheel but I did not see anything in a search on this site. The output is to the debug window. If any one wants to pretty it up, feel free.
Code:
Sub ListCustomCommandBarControls()

   Dim cbr As CommandBar
   Dim cbCtl As CommandBarControl, cbCtlA As CommandBarControl
   Dim n As Integer
   Dim cbar As CommandBar
   
   n = 1
   For Each cbr In Application.CommandBars
      Debug.Print n, cbr.Name
   Next

   Set cbar = CommandBars("Lodge")

   On Error Resume Next
   For Each cbCtl In cbar.Controls
      Debug.Print cbCtl.Caption
      For Each cbCtlA In cbCtl.Controls
         Debug.Print cbCtlA.OnAction, cbCtlA.Caption
         If Err <> 0 Then
            Debug.Print "Action=?", cbCtlA.Caption
            Err.Clear
         End If
      Next
   Next
   
End Sub
 

jdraw

Super Moderator
Staff member
Local time
Today, 09:43
Joined
Jan 23, 2006
Messages
15,362
Thanks for showing the code.
I tried it -top half worked fine.

I get Error 5 Invalid Procedure Call or Argument on this line
Code:
Set cbar = CommandBars("Lodge")
but I don't know much about command bars and nothing about "Lodge".
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:43
Joined
May 7, 2009
Messages
19,169
I thnink lodge there is custom commandbar added.
 

jdraw

Super Moderator
Staff member
Local time
Today, 09:43
Joined
Jan 23, 2006
Messages
15,362
Thanks arnel, that was my thought too.
 

Cronk

Registered User.
Local time
Tomorrow, 00:43
Joined
Jul 4, 2013
Messages
2,770
Apologies. I could have been more explicit.

'Lodge' is indeed the name of the custom command bar. (The database is for a booking system at a ski lodge). I used the first loop to enumerate all command bars to find the name of the custom command bar.
 

Users who are viewing this thread

Top Bottom