Macro: sheet protect/unprotect problem

blaksnm

Well-known Member
Joined
Dec 15, 2009
Messages
554
Office Version
  1. 365
Platform
  1. Windows
Hey Guys
I have made two OptionButtons to activate 2 different macros - both used in a protected sheet.

The macros unprotect the current sheet , do stuff and then protect it again.

Running macro1 works all right on 1st move.
However, when I run macro2 (by activating OptionButton2) after running macro1 (activated by OptionButton1) the macro will not unprotect the sheet as expected, and abend the macro.

The same result when reversing the actions.

The funny part is that when the procedure is done/macros are run by run directly in VBA - it seems to work well...!:confused:

I've obiously have missed something on the road here - but what?


Here is an extract of my macros:

Sub ActivateOptionButton1()
Application.ScreenUpdating = False
ActiveSheet.Unprotect

' Do stuff

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Application.ScreenUpdating = True
End Sub

Sub ActivateOptionButton2()
Application.ScreenUpdating = False
ActiveSheet.Unprotect

' Do stuff

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
UPS - problem solved ... :)
I was to quick on the trigger

Another question in this line:
Are there any simple way to unprotect/protect ALL sheets in the workbook as one block?
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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