Disabling right-click on sheet tab on ONLY one workbook

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
253
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2011
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 the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
3,452
Office Version
  1. 365
Platform
  1. Windows
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,186,877
Messages
5,960,372
Members
438,472
Latest member
Nate J

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
Top