Add Method (MenuItems Collection)

Applies To

MenuItems Collection.

Description

Adds a new menu item to the specified menu. Can also be used to restore a built-in menu item in Microsoft Excel that has been deleted. Returns a MenuItem object. Use the AddMenu method to add a submenu caption.

Syntax

object.Add(caption, onAction, shortcutKey, before, restore, statusBar, helpContextID, helpFile)

object

Required. The MenuItems object.

caption

Required. The text of the menu item (sets the initial value of the Caption property for the new menu item). Use an ampersand (&) before the command underline. Use a single hyphen ("-") for the caption to create a separator bar.

onAction

Optional. Specifies the name of the macro that runs when the new menu item is selected.

shortcutKey

Optional. Used only on the Apple Macintosh. Specifies the shortcut key for the menu item as text.

before

Optional. Specifies the menu item before which the new item will be added. Can be either a number (1 to insert at the top of the menu, for example) or a caption of another, existing menu item (in the language of the macro, without the ampersand), or a reference to the menu item.

restore

Optional. If True, Microsoft Excel will restore the previously deleted built-in menu item named caption. If False or omitted, Microsoft Excel will add a new menu item. The restored menu item is placed at the end of the menu unless you use the before argument to specify the location.

statusBar

Optional. Specifies help text to display in the status bar when the menu item is selected or browsed by the user. If omitted the default status bar text assigned to the macro is used.

helpContextID

Optional. Specifies the context ID for the custom help topic of the menu item. If omitted the default help context ID assigned to the macro is used.

helpFile

Optional. Specifies the help file name containing the custom help topic of the menu item. If omitted the default help file name assigned to the macro is used.

Remarks

The settings specified for the statusBar, helpContextID, and helpFile arguments override any per-macro options set by the macro specified by the onAction argument.

However, changing the macro options after the menu item has been added overrides the custom help arguments used with the Add method.

See Also

AddMenu Method, Checked Property, Enabled Property, MacroOptions Method, OnAction Property.

Example

This example adds a new menu item at the top of the Help menu on each menu bar.


For Each mb in MenuBars
    mb.Menus("Help").MenuItems.Add _
        caption:="Read Me First", _
        onAction:="Read_Me_First", _
        before:=1
Next mb