XL98: No Shortcut Keys Listed on Custom Menu Item (185368)
The information in this article applies to:
- Microsoft Excel 98 Macintosh Edition
This article was previously published under Q185368 SYMPTOMS
If you run a macro that adds a custom menu item to a menu, the macro is run
without error, but the shortcut key combination is not added next to the
menu item. Also, the shortcut key for the menu item does not function.
CAUSE
Your shortcut key combination may not be displayed next to your custom menu
item, and the shortcut key combination may not work if the macro that
creates the menu item was created in Microsoft Excel for the Macintosh,
version 5.0.
The object model for toolbars, menus and menu items has changed to the
CommandBar object model in Microsoft Excel 98 Macintosh Edition. With this
change, the Shortcutkey argument for the Add method of the MenuItems
collection is being ignored.
WORKAROUNDMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
The following example utilizes the new CommandBars object model to add a
custom menu to the worksheet menu bar. This custom menu has one menu item
added to it, and this menu item has a shortcut key combination listed next
to it.
Creating and Running the Macro- Close and save any open workbooks, and then create a new workbook.
- Start the Visual Basic Editor (press OPTION+F11).
- On the Insert menu click module.
- Enter the following in the module:
Sub Test()
'This macro is called by the "my item" menu item on the
'"my menu" menu.
MsgBox "your custom menu item"
End Sub
Sub Add_Menu()
'This will add a menu item called "my menu" to the menu bar.
Set mymenu = CommandBars("worksheet menu bar").Controls.Add _
(Type:=msoControlPopup)
mymenu.Caption = "my menu"
'This will add a menu item called "my item" to the "my menu"
'menu.
Set myitem = mymenu.Controls.Add(Type:=msoControlButton)
myitem.Caption = "my item"
myitem.OnAction = "Test"
myitem.ShortcutText = "Cmd+Option+k"
myitem.Style = 2
End Sub
- On the File menu, click "Close and Return to Microsoft Excel."
- On the Tools menu, point to Macro, and then click Macros.
- Select Test in the list of macros, and then click Options.
- Type the letter "k" in the box for the Shortcut key. Click OK.
- Select add_menu in the list of macros, and then click Run.
The custom menu item is added to the menu bar.
- Press COMMAND+OPTION+K.
The Test macro is run, and a message box is displayed.
- Click OK.
Removing the Custom Menu- Start the Visual Basic Editor (press OPTION+F11).
- Type the following code on the module you created in the previous steps:
Sub Remove_Menu()
CommandBars("worksheet menu bar").Controls("my menu").Delete
End Sub
- Run the Remove_Menu macro.
The custom menu is removed from the menu bar.
STATUS
Microsoft has confirmed this to be a problem in Microsoft Excel 98
Macintosh Edition.
REFERENCES
For more information about command bars, from the Visual Basic Editor,
click the Office Assistant, type commandbars, click Search, and then
click to view "Using command bars."
NOTE: If the Assistant is hidden, click the Office Assistant button on the
Standard toolbar. If the Assistant is not able to answer your query, please
see the following article in the Microsoft Knowledge Base:
176476 OFF: Office Assistant Not Answering Visual Basic Questions
Modification Type: | Major | Last Reviewed: | 6/17/2005 |
---|
Keywords: | kbbug kbnofix KB185368 |
---|
|