Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


unable right mouse click

Posted on 1998-09-04
Medium Priority
Last Modified: 2008-01-16

I have made toolbar in Excel. All build_in toolbar have been disabled.  But if user click my toolbar with right mouse, he can still set them back. How can I disable right_mouse_click function?

Using VBA? or  API?

Help Please!!!!

Question by:msgek
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

paddyq earned 200 total points
ID: 1613459
Do you wish for the standard built-in toolbars to be disabled?

The following may assist you in solving your problem:


       Microsoft(R) Product Support Services Application Note (Text File)

                                                        Revision Date: 9/95
                                                            1 Disk Included

     The following information applies to Microsoft Excel, version 5.0, 5.0c.

      ACCOMPANY THIS DOCUMENT (collectively referred to as an Application
      PURPOSE. The user assumes the entire risk as to the accuracy and
      the use of this Application Note. This Application Note may be
      copied and distributed subject to the following conditions:  1) All
      text must be copied without modification and all pages must be
      included;  2) If software is included, all files on the disk(s)
      must be copied without modification (the MS-DOS(R)  utility
      diskcopy is appropriate for this purpose);  3) All components of
      this Application Note must be distributed together;  and  4) This
      Application Note may not be distributed for profit.

      Copyright (C) 1995 Microsoft Corporation.  All Rights Reserved.
      Microsoft, MS-DOS, Visual Basic and Windows are registered
      trademarks of Microsoft Corporation.

                                TABLE OF CONTENTS


     How to Use the Examples in This Application Note

        Using the Vba_mnu.xls File
           To install the Vba_mnu.xls file on your hard disk
           To use Vba_mnu.xls
        Using the Examples in the Text of This Application Note

     Visual Basic Code Examples and Tips

        Menu Bars
           To save the active menu bar state (either built-in or
           To count the number of menus on the worksheet menu bar
        Menu Items
           To add a separator bar menu item
           To add a shortcut key to a menu item
           To assign a Help file to a menu item
           To add a submenu
           To delete a submenu
        Shortcut Menu Bars
        Shortcut Menus
           To add a menu item to the "Shortcut menu 1" menu bar
           To delete a menu item from a shortcut menu bar
           To restore a menu item on built-in shortcut menu bar

     Where to Find More Information

        The Object Browser
        Microsoft Knowledge Base
        FastTips System


     While many of the common tasks associated with customizing menu bars and menus can be
     accomplished with the Menu Editor (with a module sheet active, click Menu Editor on the Options
     menu), in order to get further functionality from menu bars and menus, or to tailor them for a
     custom-built application, you may want to create Visual Basic(R), Applications Edition, procedures.

     For more information about the Menu Editor, see pages 242-248 of the "Visual Basic User's Guide."

     This Application Note can help you learn some techniques for writing Visual Basic, Applications Edition, code for use with custom menus. This Application Note is
     meant to be used as a supplement to Chapter 12 ("Menus and Toolbars") of the "Visual Basic User's Guide." The Vba_mnu.xls file included with this Application Note
     contains code examples you can run. These code examples can be used with the following elements: menu bars, menu items, submenus, and shortcut menus.

     Microsoft provides examples of Visual Basic procedures 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. These Visual Basic procedures are provided 'as is' and Microsoft does not guarantee that they can be
     used in all situations. Microsoft does not support modifications of these procedures to suit customer requirements for a particular purpose.



     To use the Vba_mnu.xls file, copy it to a folder on your hard disk, and open it in Microsoft Excel.

     To install the Vba_mnu.xls file on your hard disk

        1.If you received a disk with this Application Note, insert the disk in the appropriate floppy disk drive. If you downloaded this Application Note from an online
          service, skip to step 2. This procedure assumes that you have already downloaded and extracted the compressed file.

        2.Copy the Vba_mnu.xls file from the WE1182 disk (or from the folder to which you downloaded and extracted the We1182.exe file) to the appropriate folder on
          your hard disk.

     For more information about copying files, see your Windows "User's Guide" or Windows online Help.

     To use Vba_mnu.xls

        1.Start Microsoft Excel, and click Open on the File menu.

        2.Select the folder to which you installed the Vba_mnu.xls file, select Vba_mnu.xls, and click Open.

        3.To run this example, click Menu Example on the Tools menu.

        4.To quit the example, click Restore Menus on the ResetMenu menu.


     The examples in the text portion of this Application Note demonstrate ways you can use Visual Basic, Applications Edition, code to accomplish basic tasks with menus.



     Menu bars are the objects on which menus, menu items, and submenus are built.

                                                 See this page of
                                                 the "Visual Basic
      For information about this topic           User's Guide"

      To add a new menu bar                      243-244, 250
      To activate a created or built-in menu bar 250
      To delete a custom menu bar                251
      To determine whether a menu is built-in    250
      To count the number of menu bars available 249
      To restore all built-in menu bars, menus,  251
      and menu items

     For a list of the built-in menu bars included in Microsoft Excel 5.0, see page 244 of the "Visual Basic
     User's Guide." The following table lists the menu bars that are included in Microsoft Excel 5.0 to
     maintain compatibility with earlier versions of Microsoft Excel. These menu bars are not listed in the
     "User's Guide." (To display these menus, click Options on the Tools menu, and select Microsoft Excel
     version 4.0 menus on the General tab.)

      Built in
      menu bar name          Description

      Worksheet (XL4)        The menu bar that appears when a
                             Microsoft Excel 4.0 worksheet is active.

      Chart (XL4)            The menu bar that appears when a
                             Microsoft Excel 4.0 chart is active.

      Worksheet (XL4,        The menu bar that appears when you use
      Short)                 the right mouse button to click an object
                             in a Microsoft Excel 4.0 worksheet.

      Chart (XL4,            The menu bar that appears when you use
      Short)                 the right mouse button to click an object
                             in a Microsoft Excel 4.0 chart.

     For information about Constants to use with built-in menu bars, see pages 249-250 of the "Visual Basic
     User's Guide." Constants that are not included in the "User's Guide" are listed in the following table.

      This constant      Is associated with this menu bar

      xlWorksheet4       Worksheet (XL4)

      xlChart4           Chart (XL4)

      xlWorksheetShort   Worksheet (XL4, Short)

      xlShortChart       Chart (XL4, Short)

     To save the active menu bar state (either built-in or customized)

     You may want to declare "oldMenuBar" as a public variable so that another subroutine can use it in an Auto_Close subroutine. Declaring and using the variable this way
     will reset the user's previous menu bar to its original state.

        Public oldMenuBar

        Sub MenuBars_Ex4()
           oldMenuBar = ActiveMenuBar.Index()
        End Sub

     To determine the name of the active menu bar

        Sub MenuBars_Ex5()
           MsgBox ActiveMenuBar.Caption
        End Sub


     Menus are added to either a custom or built-in menu bar.

                                                  See this page of the
      For information about this topic            "Visual Basic User's Guide"

      To add a menu to the worksheet menu bar      252

      To delete a menu from the worksheet menu     252

      To restore a deleted built-in menu on the    252
      worksheet menu bar

      To disable a menu on the worksheet menu      252

     To count the number of menus on the worksheet menu bar

        Sub Menu_Ex5()
           MsgBox MenuBars(xlWorksheet).Menus.Count
        End Sub


     Menu items can be added to or removed from either built-in or custom menus. They usually have an access key, and many of the built-in menu items contain a shortcut
     key. Menu items that have an ellipsis (...) following the caption denote a menu item that opens a dialog box. Menu items that have a small black arrow after the caption
     will display one or more submenu items.

                                                  See this page of the
      For information about this topic            "Visual Basic User's Guide"

      To add a menu item to an existing           253
      worksheet menu

      To delete a menu item                       253

      To disable a custom menu item               254

      NOTE: Built-in menu items cannot
      be disabled, only deleted.

      To add a check mark to a menu item          254

     To add a separator bar menu item

     To add a separator bar to a menu, use a hyphen in place of the caption text of a menu item.

        Sub menuitem_Ex4()
           MenuBars(xlWorksheet).Menus("&Edit").MenuItems.Add _
              Caption:="-", Before:="Delete Sheet"
        End Sub

     To add a shortcut key to a menu item

     This macro adds a menu item called "Command1" with a CTRL+K shortcut key to the Edit menu on the worksheet menu bar. It also specifies that the
     "myShortCutExample" procedure is run when you press CTRL+K.

        Sub menuItem_Ex5()
           With Application.MenuBars(xlWorksheet).Menus("&Edit")
              .MenuItems.Add Caption:="Command&1      Ctrl+K", _
              OnAction:="mnuShortCutKey", _
              StatusBar:="Short-cut key on a MenuItem"
              Application.OnKey "^k", "myShortCutExample"
           End With
        End Sub

     To assign a Help file to a menu item

     The following macro adds a menu item called "Visual Basic Help" to the Help menu on the module sheet menu bar. The OnAction property runs the
     Open_VisualBasic_Help macro, which opens the Help file.

     Note: The StatusBar property is only available on Excel 5.0c and later.

        Sub menuItem_Ex7()
          With Application.MenuBars(xlModule).Menus("&Help")
            .MenuItems.Add _
              Caption:="Visual Basic Help", _
              OnAction:="Open_VisualBasic_Help", _
              Before:=1, _
              StatusBar:="Opens Excel Visual Basic Help"
          End With
        End Sub

     This macro opens the Contents topic of the Visual Basic Help file when you select the "Visual Basic
     Help" menu item.

        Sub Open_VisualBasic_Help()
           Application.Help Application.Path & "\vba_xl.hlp", 65535
        End Sub


     Submenus appear off to the side when a menu item is selected. A menu item that has a submenu has a small black arrow located at the right end of the menu item.

     To add a submenu

     This macro adds a menu item called "Command1" to the Edit menu (on the worksheet menu bar). It then adds two submenu items to the Command1 menu item; both of
     these submenu items run a procedure called "subMenuMacro."

        Sub SubMenu_Ex1()
           With Application.MenuBars(xlWorksheet).Menus("&Edit")
              .MenuItems.AddMenu Caption:="Command1"
              .MenuItems("Command1").MenuItems.Add _
                 Caption:="Added SubMenu 1", _
              .MenuItems("Command1").MenuItems.Add _
                 Caption:="Added SubMenu 2", _
           End With
        End Sub

     The subMenuMacro macro returns the caption text of the submenu when either "Added SubMenu 1" or
     "Added SubMenu 2" is selected.

        Sub subMenuMacro()
        Dim theSubMenu As String
        theSubMenu = Application.Caller
        With Application.MenuBars(xlWorksheet).Menus("Edit")
              MsgBox .MenuItems("Command1").MenuItems(theSubMenu).Caption
           End With
        End Sub

     To delete a submenu

     This macro deletes all of the submenus from the Fill menu item on the Edit menu (on the worksheet menu bar).

        Sub SubMenu_Ex2()

        Dim subMnuItm As Object

           For Each subMnuItm In
        Application.MenuBars(xlWorksheet).Menus("&Edit"). _
           Next subMnuItm

        End Sub


     Shortcut menu bars appear when you use the right mouse button to click a specific Microsoft Excel object. Microsoft Excel has three shortcut menu bars that each have a
     variety of menus available. You cannot create custom shortcut menu bars, although the built-in menu bars are fully customizable. The following table lists all of the
     associated menus that are available for each shortcut menu bar.

      Shortcut       Shortcut       Shortcut
      Menus 1        Menus 2        Menus 3

      Toolbar        Drawing        Chart Series
      Toolbar        Button         Chart Text
      Worksheet      Text Box       Chart Plot
      Cell                          Area
      Column         Dialog Sheet   Entire Chart
      Row                           Chart Axis
      Workbook Tab                  Chart
      Macro Sheet                   Chart Floor
      Title Bar                     Chart Legend
      Watch Pane
      Debug Code


     To add a menu item to the "Shortcut menu 1" menu bar

     This macro adds a menu item to the shortcut menu that is available when the user is selecting a cell on a worksheet.

        Sub ShortCut_Ex1()
           Application.MenuBars("Shortcut Menus 1") _
              .Menus("Worksheet Cell").MenuItems.Add _
              Caption:="Add 20%", _
              OnAction:="Add_Percent", _
        End Sub

     The Add_Percent macro is run when the "Add 20%" menu item is selected in the preceding shortcut
     menu bar example.

        Sub Add_Percent()
           Dim temp As Variant
           temp = ActiveCell.Value
              If IsNumeric(temp) Then ActiveCell.Value = temp * 1.2
        End Sub

     To delete a menu item from a shortcut menu bar

         Sub Shortcut_Ex2()
            With Application.MenuBars("Shortcut Menus
         1").Menus("Worksheet Cell")
              .MenuItems("Clear Contents").Delete
            End With
         End Sub

     To restore a menu item on built-in shortcut menu bar

     This macro restores the "Clear Contents" menu item that was deleted in the example above.

         Sub Shortcut_Ex3()
           With Application.MenuBars("Shortcut Menus 1")
              .Menus("Worksheet Cell").MenuItems.Add _
              Caption:="Clear Contents", _
              Before:=8, _
          End With
         End Sub



     A complete list of all of the properties and methods for a specific menu item is available in the Object Browser. To find this information, switch to a Visual Basic module,
     click Object Browser on the View menu, and then select the name of the control you want from the Excel Libraries/Workbooks list.

     For more information about using the Object Browser, see pages 77-79 of the "Visual Basic User's Guide."


     The Microsoft Knowledge Base is a primary Microsoft product information source for Microsoft support engineers and is also available to Microsoft customers. This
     comprehensive database contains more than 40,000 detailed articles with technical information about Microsoft products, fix lists, documentation errors, and answers to
     commonly asked technical support questions. These articles are also available through The Microsoft Network, the Microsoft TechNet CD-ROM, and the Microsoft
     Developer Network CD-ROM.


     Microsoft FastTips is an automated, toll-free service that provides technical information about key Microsoft products and is available 24 hours a day, 7 days a week in the
     United States and Canada. Using the FastTips system, you can receive automated answers to common technical problems and access popular articles from the Microsoft
     Knowledge Base. This information is delivered over the phone through recorded voice scripts, by fax, or through the U.S. mail.

        Home Products FastTips                 (800) 936-4100
        Desktop Applications FastTips          (800) 936-4100
        Desktop Systems FastTips               (800) 936-4200
        Development Tools FastTips             (800) 936-4300
        Business Systems FastTips              (800) 936-4400

LVL 16

Expert Comment

ID: 6243192
When you right-click over the toolbars or the menu, the appearing shortcut-menu is a commandbar called "Toolbar List". You can disable it with:

CommandBars("ToolBar List").Enabled = False

This will Not work for Excel versions prior to 97 SR1.
(bugg fixed in 97 SR1)

Hope this will help.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question