Disabling right-click on sheet tab on ONLY one workbook

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
305
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I would like to disable the ability for the user to right-click on any of the sheet tabs in a particular workbook. I ran across a web page that talked about how to do it, using this code in the ThisWorkbook module:

Code:
<code class="vb keyword">
Private</code> <code class="vb keyword">Sub</code> <code class="vb plain">Workbook_BeforeClose(Cancel </code><code class="vb keyword">As</code> <code class="vb keyword">Boolean</code><code class="vb plain">)</code><code class="vb spaces">
</code><code class="vb plain">
   Application.CommandBars(</code><code class="vb string">"Ply"</code><code class="vb plain">).Enabled = </code><code class="vb keyword">True</code>

<code class="vb keyword">End</code> <code class="vb keyword">Sub</code>
  

<code class="vb keyword">Private</code> <code class="vb keyword">Sub</code> <code class="vb plain">Workbook_Open()</code>

<code class="vb spaces">    </code><code class="vb plain">Application.CommandBars(</code><code class="vb string">"Ply"</code><code class="vb plain">).Enabled = </code><code class="vb keyword">False</code>

<code class="vb keyword">End</code> <code class="vb keyword">Sub</code>

This works. HOWEVER, if I am running the workbook in question with this code inside, and then I open ANOTHER workbook, the right-click is disabled on that workbook, also. I ONLY want it to be disabled on the one workbook that has the above code in it. How can I do that?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Add these :
Code:
Private Sub Workbook_Activate()
Application.CommandBars("Ply").Enabled = False
End Sub


Private Sub Workbook_Deactivate()
Application.CommandBars("Ply").Enabled = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top