Disable Some Right Mouse Click Options

  • Hi All, Does anyone know a way, using VBA code, to disable/enable individual shortcut menu items that are are made available with a right mouse button click. The following code disables the right mouse button completely but I would like to disable only a couple of options like the 'Cut' option.


    Thank you for any help.


    The code to disable is below and to re-enable I just change False to True.


    Code
    Dim cb As CommandBar
    i = 0
    For Each cb In CommandBars
        If cb.Type = msoBarTypePopup Then cb.Enabled = False
    Next cb
  • Re: Disable Right Mouse Button Options


    Drop this code into the Private Module of the Workbook Object (ThisWorkbook);

  • Re: Disable Some Right Mouse Click Options


    The CommandBar does not reset itself. So once the comman is disabled it is not available to other workbooks even after quiting and recalling Excel. So I think the code below would work better.


    Code
    Private Sub Workbook_Activate()
        With Application.CommandBars("Cell")
            .Controls("Cut").Enabled = False
            .Controls("Copy").Enabled = False
    End Sub


    Code
    Private Sub Workbook_Deactivate()
        With Application.CommandBars("Cell")
            .Controls("Cut").Enabled = True
            .Controls("Copy").Enabled = True
        End With
    End Sub

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

  • Re: Disable Some Right Mouse Click Options


    Thanks bill, your code works perfectly for the right click menu options that doe not have sub menus like the 'Paste Special', 'Insert' and 'Delete' controls. Are you able to say how to temporarily make tham, unavailable too please.


    Thanks for your help


    CDT

  • Re: Disable Some Right Mouse Click Options


    I tried using the options below but I can't be coding it correctly because neither work.



    Code
    Sub t1()
    With Application.CommandBars("Cell")
    
    
        .Controls("Insert shift cells right").Enabled = False
        
    End With
    End Sub


    or


    Code
    Sub t1()
    With Application.CommandBars("Cell")
    
    
        .Controls("shift cells right").Enabled = False
    
    
    End With
    End Sub
  • Re: Disable Some Right Mouse Click Options


    Hi there,


    Just type in the name of the control as it appears in the right click menu (i.e. include the "...")




    p.s. End code tag is [/CODE] not [CODE/] :smile:


    Cheers,
    Averil

    -------------
    [FONT="Comic Sans MS"]Averil Pretty[/FONT]

  • Re: Disable Some Right Mouse Click Options


    The (…) after the word Delete indicate that the menu item when clicked will display a dialog box (not a sub menu). Therefore you cannot “disable” any selection on he dialog box. A work around would be to disable the Delete and add a custom menu selection calling a custom dialog box with what you want to allow the user to do.



    Code
    Sub t1()
        With Application.CommandBars("Cell")
            .Controls("Delete...").Enabled = False
        End With
    End Sub

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!