
Tips.Net > ExcelTips Home > Customizing Excel > Menus > Changing the Shortcut Menu
Summary: If you want to change the Context menus used in Excel, on purpose, here’s how to go about it. Just create a macro and make the change to the controls on a CommandBar. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)
The shortcut menus that you see when you right-click on different objects can be very helpful. In Word, it is relatively easy to change the shortcut menus. In Excel, however, changing the menus—while possible—is nowhere near as easy.
In Excel, you can only change the options on a shortcut menu by using VBA. The exact code you use depends on whether you are removing items from a shortcut menu or adding them in. The following code illustrates how to delete an item from a shortcut menu:
Sub Del_Item()
CommandBars("Cell").Controls("Cut").Delete
End Sub
Each shortcut menu is really a member of the CommandBars collection, and can thus be manipulated in VBA. In this case, a CommandBar by the name of "Cell" is being manipulated. This just happens to be the command bar for the shortcut menu that appears when you right-click on a cell in a worksheet. Excel has 47 named shortcut menu CommandBars.
If you want to add a command to a shortcut menu, all you do is use code similar to the following:
Sub Add_Item()
CommandBars("Cell").Controls.Add _
Type:=msoControlButton, Id:=21, _
Before:=1
End Sub
In this instance you are again manipulating the shortcut menu that appears when you right-click on a cell. You are adding a command that is defined by the Id value setting. In this case, the Id value is 21, which represents the Cut command. There are scores, if not hundreds, of different command IDs within Excel.
To aid you in determining both the Id to use for a command, as well as the names of the various shortcut menu CommandBars, you should refer to the Knowledge Base article 213552. This article is quite long, and can be found at the following address:
http://support.microsoft.com/?kbid=213552
The article is written for Excel 2000, but is also applicable to later versions of Excel, through Excel 2003. In Excel2007 there are still CommandBars, but it can be hit-and-miss trying to see what will work with them. In my testing it appears that the CommandBars for the Context menus (or, if you prefer, shortcut menus) are all available in Excel 2007. What can be bothersome is trying to figure out what the proper command IDs are for the various commands available in Excel 2007.
Tip #1962 applies to Microsoft Excel versions: 97 2000 2002 2003 2007
More Power! For some people, the prospect of creating macros can be scary. Those who conquer their fears, however, find they become much more confident and productive once they learn how to make Excel do exactly what they want. ExcelTips: The Macros is an invaluable source for learning Excel macros. You are introduced to the topic in bite-sized chunks, pulled from past issues of ExcelTips. Learn at your own pace, exactly the way you want.
Check out ExcelTips: The Macros today!
Have thousands of ExcelTips at your fingertips, on your own system. Answer your own questions or help support others. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site