This section is talking about disabling right-click menu in specified worksheet with VBA method. Please do as follows.1.
Open the worksheet you want to disable the right-click menu, right click the sheet tab and then click View Code from the context menu.2. Then the Microsoft Visual Basic for Applications window pops up. Please copy and paste the below VBA script into the Code window.VBA code: Disable the right-click menu in specified worksheet in Excel Private Sub WorksheetBeforeRightClick(ByVal Target As Range, Cancel As Boolean)Cancel = TrueMsgBox ('Sorry Right Click is Disbaled for this Worksheet'), vbInformation, 'Kutools for Excel'End Sub3. Press the Alt + Q keys to exit the Microsoft Visual Basic for Applications window.From now on, when you try to right click on any cell of this worksheet, you will get a Kutools for Excel dialog box as below screenshot shown.Disable the right click menu in the whole workbook with VBA codeYou can also disable the right-click menu in the whole workbook with the following VBA code.1. In the workbook you need to disable the right-click menu, please press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.2. In the Microsoft Visual Basic for Applications window, please double click ThisWorkbook in the left Project pane, then copy and paste the below VBA code into the ThisWorkbook (Code) window.
Before Excel 2007, VBA programmers used the CommandBar object for creating custom menus, custom toolbars, and custom shortcut (right-click) menus. Beginning with Excel 2007, the CommandBar object is in a rather odd position. If you write code to customize a menu or a toolbar, Excel intercepts that code and ignores many of your commands.
See screenshot:VBA code: Disable the right-click menu in the whole workbook in Excel Private Sub WorkbookSheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)Cancel = TrueMsgBox ('Sorry Right Click is Disbaled for this Workbook'), vbInformation, 'Kutools for Excel'End Sub3. Press the Alt + Q keys to exit the Microsoft Visual Basic for Applications window.From now on, when you try to right click on any cell in the workbook, a Kutools for Excel dialog box will pop up to remind you the right-click menu has been disabled. See screenshot:Related articles:.
Kutools for Excel - The Best Office Productivity Tool Increase Your Productivity by80%. Reuse: Quickly insert complex formulas, chartsĀ and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails. Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range. Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns.