Finding the worksheet's protection status and setting worksheet protection status back to initial status

stubarny

New Member
Joined
Apr 7, 2011
Messages
41
Hello,

Please could you tell me how to find the current worksheet protection status (protected/unprotected), carry out my code and then reset the worksheet's status back to what it was before the macro started?

I think Worksheet("Name").Protect/Unprotect is a function, not a property?

Thanks for your help,

Stu
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try like this

Code:
Dim ptc As Boolean
ptc = Sheets("sheet1").ProtectContents
If ptc Then Sheets("Sheet1").Unprotect
'
'more code
'
If ptc Then Sheets("Sheet1").Protect
 
Upvote 0
Thanks VoG, out of curiosity is it correct to say that the property "Sheets("sheet1").ProtectContents" can't be set directly?

Stu
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,259
Members
452,901
Latest member
LisaGo

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