GetMenuItems

The following routine gets all the menu items in the PowerPoint menu bar.

Sub GetMenuItems(ByVal MenuItems As Collection, _
    ByVal CBP As CommandBarPopup, ByVal Indent As Long)

    Dim CBC As CommandBarControl
    Dim IndentStr As String

    IndentStr = Space(Indent * 4)

    For Each CBC In CBP.Controls
        MenuItems.Add IndentStr + CBC.Caption
        If CBC.Type = msoControlPopup Then
            GetMenuItems MenuItems, CBC, Indent + 1
        End If
    Next
End Sub

Sub GetMenuBarItems(ByVal MenuItems As Collection)
    Dim CBC As CommandBarControl

    For Each CBC In CommandBars("Menu Bar").Controls
        GetMenuItems MenuItems, CBC, 0
    Next
End Sub

The following routine uses the GetMenuBarItems listed above

Sub PrintMenuBarItems()
    Dim MenuItems As New Collection
    Dim S As Variant

    GetMenuBarItems MenuItems

    For Each S In MenuItems
        Debug.Print S
    Next
End Sub

Contact OfficeOne on email at officeone@officeoneonline.com. Copyright © 2001-2023 OfficeOne. All rights reserved.