Disable shapes when Workbook is protected VBA

julhs

Active Member
Joined
Dec 3, 2018
Messages
407
Office Version
  1. 2010
Platform
  1. Windows
I have several shapes on the worksheet that have macros assigned to them.
I want to specifically disable/deactivate those SHAPES while the sheet is PROTECTED.
Reason being is that at the moment when the sheet is PROTECTED (via VBA) and I then subsequently click on one of the shapes it causes the assigned Sub to not run/freeze/bug out.
So I thought the best approach would be to disable/deactivate those shapes while the Sheet is PROTECTED.
There are other "btn" shapes on the sheet, if they can be disable/deactivate on mass then it would avoid the need to name them individualy
But to date none of my attempts have worked.
This is my last failed attempt:
VBA Code:
Sub ProtectSheet()
ActiveSheet.Protect ActiveSheet.Shapes("btnSelectTheSubToRun").ControlFormat.Enabled = False
End Sub
 
Change that line to:
VBA Code:
ActiveSheet.Unprotect
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Thanks Mumps
With your help I have it running.
Dropping the use of the “Call” event made far more sense as it still needed an “If MsgBox” in the Main Sub to EXIT that if the answer in the “Called” Sub was NO, so was overly convoluted/long winded.
The below is the final draft and works entirely within the Main Sub
VBA Code:
> .. Main Sub beginning code here….
   If ActiveSheet.ProtectContents = True Then
   If MsgBox("The Sheet is PROTECTED Do you want to continue?", _
            vbQuestion + vbYesNo) = vbNo Then
     Exit Sub
  Else
     ActiveSheet.Unprotect
  End If
End If
> ..Main Sub code continues….

Really appreciate your help.
Julhs
 
Upvote 0

Forum statistics

Threads
1,215,068
Messages
6,122,950
Members
449,095
Latest member
nmaske

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