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

sneel3

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

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Pyromantic

Board Regular
Joined
Aug 9, 2006
Messages
58
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"
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539

ADVERTISEMENT

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!
 

stuartford

Active Member
Joined
Nov 28, 2002
Messages
419
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
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539

ADVERTISEMENT

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

"111"

not

111
 

stuartford

Active Member
Joined
Nov 28, 2002
Messages
419
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
 

sneel3

Active Member
Joined
Oct 9, 2002
Messages
331
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
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
You have the wrong syntax!

The ":" is not optional!

Use this form:

ActiveSheet.Protect Password:="password"
 

Forum statistics

Threads
1,136,345
Messages
5,675,225
Members
419,555
Latest member
Paddington

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