XL: Visual Basic Example to Disable All Shortcut Menus

ID: Q131257

The information in this article applies to:

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, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/

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:

   ARTICLE-ID: Q161440
   TITLE     : 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

REFERENCES

"Microsoft Excel 5 Visual Basic for Applications Reference," version 5.0, "ShortcutMenus Method," page 608

For more information about ShortcutMenus, choose Contents from the Help menu. Choose Programming With Visual Basic and then choose Search and type

   ShortcutMenus

Additional query words: 5.00 5.00a 5.00c 7.00 7.00a XL7 XL5
Keywords          : kbcode kbprg PgmHowto 
Version           : WINDOWS:5.0,5.0c,7.0,7.0a; MACINTOSH:5.0,5.0a
Platform          : MACINTOSH WINDOWS
Issue type        : kbhowto

Last Reviewed: May 18, 1999