How to disable the right click menu in specified worksheet or whole workbook in Excel?
Do you know how to disable the right click menu in Excel? This article will show you methods to disable the right click menu not only in specified worksheet but also in the whole workbook.
Disable the right click menu in specified worksheet with VBA code
Disable the right click menu in the whole workbook with VBA code
Disable the right click menu in specified worksheet with VBA code
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 Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
MsgBox ("Sorry Right Click is Disbaled for this Worksheet"), _
vbInformation, "Kutools for Excel"
End Sub
3. 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 code
You 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. See screenshot:
VBA code: Disable the right-click menu in the whole workbook in Excel
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Cancel = True
MsgBox ("Sorry Right Click is Disbaled for this Workbook"), _
vbInformation, "Kutools for Excel"
End Sub
3. 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:
- How to disable cut, copy and paste functions in Excel?
- How to disable right click on sheet tab in Excel?
- How to prevent or disable edit mode by double clicking cell in Excel?
Best Office Productivity Tools
Supports Office/Excel 2007-2021 and 365 | Available in 44 Languages | Easy to Uninstall Completely
Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need Is Just A Click Away...
Supercharge Your Spreadsheets: Experience Efficiency Like Never Before with Kutools for Excel (Full-Featured 30-Day Free Trial)
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
