Sheet protection - passwords

ElvisSteel

Board Regular
Joined
Mar 23, 2009
Messages
122
Hi
I have the following macro...
Sub ProtectSheets()
Sheets("Outlook").Protect EnableSelection = xlNoSelection
Sheets("FY Utilisation Report").Protect EnableSelection = xlNoSelection
Sheets("Resource Check").Protect EnableSelection = xlNoRestrictions
Sheets("Project").Protect
Sheets("Reports 1").Protect EnableSelection = xlNoSelection
Sheets("Reports 2").Protect EnableSelection = xlNoSelection
Sheets("Tables").Protect
Sheets("Input").Protect
End Sub

When I run this, all of these are protected, but when I try to unprotect them (using the ribbon button) all of the sheets where I have specified xlNoSelection now require a password!
I don't know what the password is, so I am basically stuck.
Any ideas as to....
1. Why this is happening?
2. What the password may be?

Thanks
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
You have missed a colon in:

Sheets("Outlook").Protect EnableSelection:= xlNoSelection

So instead of using the named argument EnableSelection the statement:

EnableSelection = xlNoSelection

is used as the first argument, which happens to be Password.
 
Upvote 0
Andrew,

Thanks for that - beginners error, but I am unable to unlock the sheet using "EnableSelection = xlNoSelection" as the password
Also do you know why the other sheets are not password protected?
It is only those with xlNoSelection that have a password.
 
Upvote 0
Did you surround EnableSelection = xlNoSelection with quotes when you tried to unprotect the sheet (in code)? If so try removing them. The other sheets don't have a password because you didn't set one when you protected them.
 
Upvote 0
Andrew,

Thanks so much for your instant response

The code...
Code:
Sheets("Reports 2").Unprotect Password:=EnableSelection = xlNoSelection
...unprotected the sheet

I'm still a little uncertain as to why the "Resource Check" sheet did not have a password set (as I had specified xlNoRestrictions with the colon missing), but for now the problem is solved and a lesson learned!

Regards

Steve
 
Upvote 0
What does this return?

MsgBox EnableSelection = xlNoRestrictions

By the way, I strongly advise you to check Require Variable Declaration under Tools|Options|Editor tab. That way Option Explicit will appear at the top of each new module and your project won't compile if there are any undeclared variables.
 
Upvote 0

Forum statistics

Threads
1,223,719
Messages
6,174,089
Members
452,542
Latest member
Bricklin

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