Microsoft KB Archive/131257

= Visual Basic Example to Disable All Shortcut Menus =

Article ID: 131257

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 95a
 * Microsoft Excel 5.0 Standard Edition
 * Microsoft Excel 5.0c
 * Microsoft Excel 5.0a for Macintosh

-



This article was previously published under Q131257



SUMMARY
In Microsoft Excel, you can use the ShortcutMenus method to disable shortcut menus.



MORE INFORMATION
Microsoft 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. For information about how to disable shortcut menus in Microsoft Excel 97 for Windows and Microsoft Excel 98 Macintosh Edition, please see the following article in the Microsoft Knowledge Base:

161440 XL97: How to Disable Shortcut Menus

Use the following macros to disable and then re-enable the shortcut menus in Microsoft Excel versions 5.0 and 7.0. Sub DisableShortcutMenus Dim i As Integer Dim x As Integer Dim y As Integer On Error Resume Next For i = 1 To 3 ' Loops through three times using the index number. Application.ShortcutMenus(i).Enabled = False Next i      For x = 6 To 9 ' Loops through four times using the index number. Application.ShortcutMenus(x).Enabled = False Next x      For y = 11 To 24 ' Loops through 14 times using the index number. Application.ShortcutMenus(y).Enabled = False Next y      With Application ' These are constants that do not fall in any sequential order ' so they need to be done separately using the constant string. .ShortcutMenus(xlRowHeader).Enabled = False .ShortcutMenus(xlModule).Enabled = False .ShortcutMenus(xlDialogSheet).Enabled = False .ShortcutMenus(xlColumnHeader).Enabled = False End With End Sub

Sub RestoreShortcutMenus Dim i As Integer Dim x As Integer Dim y As Integer On Error Resume Next For i = 1 To 3 ' Loops through three times using the index number. Application.ShortcutMenus(i).Enabled = True Next i      For x = 6 To 9 ' Loops through four times using the index number. Application.ShortcutMenus(x).Enabled = True Next x      For y = 11 To 24 ' Loops through 14 times using the index number. Application.ShortcutMenus(y).Enabled = True Next y      With Application ' These are constants that do not fall in any sequential order ' so they need to be done separately using the constant string. .ShortcutMenus(xlRowHeader).Enabled = True .ShortcutMenus(xlModule).Enabled = True .ShortcutMenus(xlDialogSheet).Enabled = True .ShortcutMenus(xlColumnHeader).Enabled = True End With End Sub The following is a list of the Microsoft Excel 5.0 and 7.0 constants and the values they represent.   Shortcut menu constant     Constant Value -  xlRowHeader                    -4153 xlModule                      -4141 xlDialogSheet                 -4116 xlColumnHeader                -4110 xlToolbar                         1 xlToolbarButton                   2 xlWorksheetCell                   3 xlWorkbookTab                     6 xlMacroSheet                      7 xlTitleBar                        8 xlDesktop                         9 xlWatchPane                      11 xlImmediatePane                  12 xlDebugCodePane                  13 xlDrawingObject                  14 xlButton                         15 xlTextBox                        16 xlChartSeries                    17 xlChartTitles                    18 xlPlotArea                       19 xlEntireChart                    20 xlAxis                           21 xlGridline                       22 xlFloor                          23 xlLegend                         24

