VBA locking sheets password error

Enzo_Matrix

Board Regular
Joined
Jan 9, 2018
Messages
113
I wrote some code to protect all my sheets at once with a password and it works great when executed with F5.

when I try to unprotect the sheets manually with the same password I get the error message:
"The password you supplies is not correct. Verify that the CAPS LOCK key is off and be sure to use correct capitalization."
So I wrote the exact same code but with 'unprotect'.

Any ideas why it won't let me unprotect my sheets manually?

Code:
Sub ProtectAll()

For Each sht In ActiveWorkbook.Sheets
    sht.Protect Password = "123"
    Next
End Sub


Sub unlockall()

For Each sht In ActiveWorkbook.Sheets
    sht.Unprotect Password = "123"
   Next
End Sub
 

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).
Because you have quotes around the number it becomes a string rather than numerical.
Whereas when you key the password manually it will be numeric

Interestingly if you set the password like
Code:
activesheet.protect  "123"
then you can unlock it manually
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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