MenuItems Collection Object

Description

A collection of all the MenuItem objects on the specified menu.

Accessors

Use the Add method to add a new menu item to a menu. Use the AddMenu method to add a submenu. The following example adds a new menu item to the Help menu on the Visual Basic Module menu bar.


MenuBars(xlModule).Menus("help").MenuItems.Add "More Help"

Use the MenuItems method with an argument to access a single member of the collection or without an argument to access the entire collection at once. The following example creates a list on worksheet one that contains the menu items in the File menu on the Visual Basic Module menu bar.


Sub EnumerateFileMenu()
    Worksheets(1).Activate
    For r = 1 To MenuBars(xlModule).Menus("file").MenuItems.Count
        Worksheets(1).Cells(r, 1) = MenuBars(xlModule). _
            Menus("file").MenuItems(r).Caption
    Next
End Sub

Properties

Application Property, Count Property, Creator Property, Parent Property.

Methods

Add Method (MenuItems Collection), AddMenu Method, Item Method.