Disable shapes when Workbook is protected VBA

julhs

Active Member
Joined
Dec 3, 2018
Messages
476
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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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