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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,154
What is "FrontSheet"? Is that the name on the tab?
 

JamesW

Well-known Member
Joined
Oct 30, 2009
Messages
1,197
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"
 

Mikeykt

New Member
Joined
Feb 10, 2011
Messages
47
Sorry,

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

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

Forum statistics

Threads
1,141,842
Messages
5,708,916
Members
421,598
Latest member
NewHere

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
Top