How To Disable The Right Click Menu In Specified Worksheet Or Whole Workbook In Excel?


The context menu, commonly referred to as the right−click menu, gives users a quick method to access several Excel settings and instructions. To avoid unintentional changes to your data or unauthorised access, you might want to block or limit the right−click menu's functionality in several circumstances. In this tutorial, we'll look at detailed methods for turning off Excel's right−click menu. We'll go over two scenarios− turning off the right−click menu for the full workbook and just one worksheet. The Visual Basic for Applications (VBA) editor and worksheet protection settings are two built−in Excel capabilities that will be used to enforce these limitations.

This article will provide you the skills to manage Excel's right−click capability, whether you want to safeguard a single worksheet or the entire workbook. You may improve the security and integrity of your Excel files by following the supplied instructions, preventing unauthorised changes, and making sure that your data is kept secure. So let's get started with the tutorial and discover how to disable the right−click menu in Excel for either a specific worksheet or the entire workbook!

Disable The Right Click Menu In Specified Worksheet Or Whole Workbook

So let us see a simple process to learn how you can disable the right−click menu in a specified worksheet or whole workbook in Excel.

Step 1

Consider any Excel workbook that contains multiple worksheets. First, right−click on the sheet name and select "View Code" to open the VBA application, then double−click on the sheet name where you want to disable it.

Right click > View code > Double click .

Step 2

Then copy the below code into the text box, similar to the below image.

Code

Private Sub Workbook_Open()
   Dim ws As Worksheet
   For Each ws In Me.Worksheets
      ws.Protect
   Next ws
End Sub

Step 3

Then use ATL + Q to close the VBA and close the sheet. From now on, when you right−click on the sheet, it will return an error.

Note −

If you want to disable the right−click menu for all the workbooks, double−click on this workbook and use the below code.

Code

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

Conclusion

In this tutorial, we have used a simple example to demonstrate how you can disable the right−click menu in a specified worksheet or whole workbook in Excel to highlight a particular set of data.

Updated on: 11-Jul-2023

77 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements