Welcome toExcel.Tips.Net
Tips.Net Home
ExcelTips Home
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Learn Access Now
Free Printable Forms
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site
Adding a Little Animation to Your Life
Converting a Range of URLs to Hyperlinks
Making the Formula Bar Persistent
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.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (1962) applies to Microsoft Excel versions: 97 2000 2002 2003 2007
Change Formatting Based On Your Data! Conditional formatting provides a way for you to adjust the appearance of your data based on the data itself. Discover how to put this amazingly powerful feature to work for you, today. This comprehensive volume is available in two editions.