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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

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