My macro will not run b/c the sheet is protected

sneel3

Active Member
Joined
Oct 9, 2002
Messages
334
how can I have the macro turn off the protection at the beginning and turn it back on at the end?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
If it's passworded you would need to do this to protect it:

Code:
Sheets("Sheet1").Protect Password:="password"

And this to unprotect

Code:
Sheets("Sheet1").Unprotect Password:="password"
 
Upvote 0
You know, just as a tip for the future;

Record a macro, doing all the steps you need to do someting, like un-Protect and protect. In many cases the recorded code will show you a way to do something that may help or point you in the right direction.

In this case, due to the password, all the code will be recorded except the password part!
 
Upvote 0
just out of interest
if i rune the following code
ActiveSheet.Protect password = 111

IE same as your minus the ":" and "", excel still pasword protects the sheet but not with 111 as the password

anyideas what it is using?

Stuart
 
Upvote 0
Even if the password is Numbers they must be entered in as Text so use:

"111"

not

111
 
Upvote 0
ok thanks for tat but even if i changed the password to
ActiveSheet.Protect password = "stu"

then
when trying to manually unprotect the sheet

stu isnt the password

any ideas

this isnt a problem im just interested in whats happening

Stu
 
Upvote 0
I have the following code in the macro. It was written by the Macro Wizard, but the macro errors out when it gets to this point. Why is it erroring out?

ActiveSheet.Protection.AllowEditRanges.Add Title:="Range1", Range:=Range("L11:P65536")
ActiveSheet.Protection.AllowEditRanges.Add Title:="Range2", Range:=Range("U11:Z65536")
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingRows:=True, AllowDeletingRows:= _
True, AllowFiltering:=True
 
Upvote 0
You have the wrong syntax!

The ":" is not optional!

Use this form:

ActiveSheet.Protect Password:="password"
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,488
Members
448,967
Latest member
visheshkotha

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