Solved Layout View's CommandBarControl ID (1 Viewer)

KitaYama

Well-known member
Local time
Today, 12:49
Joined
Jan 6, 2022
Messages
1,541
I'm trying to add Layout View to a custom context menu for some forms, but can not find the ID for this CommandBarControl.
All I could find was the ID for Design View is 2952.

As a further goal, is there anywhere that lists all IDs for all CommandBarControls on all commandBar?
I tried to write a code and pass the name of a context menu and receive a list of its controls and IDs, but failed.

Any kind of help is much appreciated.
 

Edgar_

Active member
Local time
Yesterday, 22:49
Joined
Jul 8, 2023
Messages
431
Have you tried something like this?

Code:
Sub DisplayCommandBarsAndControls()
    Dim app As Application
    Set app = Application

    Dim cb As Object, ct As Object
    Dim result As String
  
    For Each cb In app.CommandBars
        result = result & "CommandBar: " & cb.Name & " (Id: " & cb.id & ") - Controls: "
      
        For Each ct In cb.Controls
            result = result & ct.Caption & ", "
        Next ct
      
        If Len(result) > 0 Then
            result = Left(result, Len(result) - 2)
        End If
      
        Debug.Print result
        result = ""
    Next cb
End Sub

Basically, that info is in Application.CommandBars. Each CommandBar has a Controls collection where you can find all about it.
 

Josef P.

Well-known member
Local time
Today, 05:49
Joined
Feb 2, 2023
Messages
827
Layout view id: 13157

Code:
Dim cb As CommandBar
Dim cc As CommandBarControl

For Each cb In Application.CommandBars
    For Each cc In cb.Controls
        If Replace(cc.Caption, "&", vbNullString) = "Layout View" Then
            Debug.Print cb.Name, cc.Caption, cc.id
        End If
    Next
Next
 

KitaYama

Well-known member
Local time
Today, 12:49
Joined
Jan 6, 2022
Messages
1,541
Thanks to all.

I was able to find the ID with the addin @isladogs suggested.
Turned back here to thank him and found other replies.

I don’t think anyone will ever need to add ”Layout View” to a custom context menu, but if anyone needs it in future, the ID is 13157 as @Josef P. replied.

Million thanks to all.
 

Users who are viewing this thread

Top Bottom