Example Adding an Item to an Existing Menu

Of course, rather than creating a custom toolbar or adding a custom menu to Excel's menu system, you may prefer to add a button to an existing toolbar or a menu item to an existing menu. In that case, you simply need to retrieve a reference to the CommandBar object to which you wish to add the item and call the Controls collection's Add method to add an item to it. In addition, you can retrieve the Index property of the item before which you'd like to position your new menu item or toolbar button. Example 12-9, which contains the source code for a Workbook_Open event that adds an "About SRXUtils" menu item immediately before the "About Microsoft Excel" item, shows how this can be done. Note that the procedure is able to determine the precise location of the About Microsoft Excel menu item by retrieving a reference to its CommandBarControl object and its Index property.

0 0

Post a comment