Results 1 to 3 of 3

Thread: Excel VBA Disabling Right Click Menus

  1. #1

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126

    Excel VBA Disabling Right Click Menus

    Does anyone know how to disable or modify the right click menu that appears when you right click on a) the scrollbar and b) the Status Bar in Excel.

    I tried the Workbook_SheetBeforeRightClick event but it has no effect on these excel components.

  2. #2
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    This should disable the popup on the status bar:

    VB Code:
    1. Application.CommandBars("AutoCalculate").Enabled = False
    As you can see, that applies to the whole application. If you just want it disabled for a workbook you can use that code to toggle it in the Workbook Activate/Deactivate events.

    For more info on working with CommandBars (like adding controls, etc.) see the Excel VBA help file topic "CommandBar Object".

    I don't have any popups on the scrollbars (Excel 2000). There is probably some documentation of all the built-in CommandBars somewhere, but I just use the code below to find the CommandBar name. Kepp in mind that if a letter is underlined, that means there is an amersand before the letter in the actual control caption.

    VB Code:
    1. Sub FindCommandBar()
    2.  
    3.     Dim cb As CommandBar
    4.     Dim cbc As CommandBarControl
    5.     Dim strControlCaption As String
    6.    
    7.     strControlCaption = "&None"
    8.  
    9.     For Each cb In Application.CommandBars
    10.         For Each cbc In Application.CommandBars(cb.Name).Controls
    11.             If cbc.Caption = strControlCaption Then
    12.                 Debug.Print cb.Name
    13.                 Exit For
    14.             End If
    15.         Next cbc
    16.     Next cb
    17.  
    18. End Sub

  3. #3

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    Works like a charm. Thanks.

    But I still don't understand why the following code still leaves that menu. Especially when your code makes an explicit reference to a member of the commandbar collection.

    Dim bar As CommandBar
    For Each bar In Application.CommandBars
    bar.Enabled = False
    Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width