Unprotecting and Protecting workbooks using VBA

Mikeykt

New Member
Joined
Feb 10, 2011
Messages
47
Hi,

I'm trying to unproect and protect my workbook, so that my script can update the cells it needs to within my macro and then reprotect the workbook so that no one can overwritethe formulas.

I've tried the VBA below but it's not quite working, any tips anyone?

Thanks

ActiveWorkbook.FrontSheet.Unprotect Password:="password"
Range("D13:P24").Select
Selection.Locked = False
Selection.FormulaHidden = False
Range("D13:P24").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect Password:="password". DrawingObjects:=True, Contents:=True, Scenarios:=True
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Not sure what you are trying to do exactly, you have "FormulaHidden = False" twice and its not hidden as default, so basically you are unlocking a cell then locking it again straight after?

To lock sheets, try:

Code:
Sheets("FrontSheet").Unprotect Password:="password"
Sheets("FrontSheet").Protect Password:= "password"
 
Upvote 0
Sorry,

I included both protect and unprotect in the same vba for now.

I will split it around the macro i've written afterwards.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

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