Adding menu items to a shortcut menu

Adding a menu item to a shortcut menu works just like adding a menu item to a regular menu. You need to know the Index or the Caption for the shortcut menu. See the preceding section to find out how to get a list of all shortcut menus.

The following example demonstrates how to add a menu item to the shortcut menu that appears when you right-click a cell. The Caption for this shortcut menu is Cell. This menu item is added to the end of the shortcut menu.

Sub AddItemToShortcut()

Dim NewItem As CommandBarControl Set NewItem = CommandBars("Cell").Controls.Add NewItem.Caption = "Toggle Word Wrap" NewItem.OnAction = "ToggleWordWrap" NewItem.BeginGroup = True End Sub

Selecting the new menu item executes the ToggleWordWrap procedure.

0 -1

Post a comment