Forum Discussion
esatyilmaz
Jul 14, 2022Copper Contributor
Excel 365 VBA vs Review>Protect Sheet password
Hello,
I am encountering a strange issue. I lock a worksheet by Review>Protect Sheet and set a worksheet password such as 0010 and then in the VBA code I want to unprotect with the same password to run a piece of code. But it generates an error saying password doesn't match. Below is the code I use to unprotect.
Application.Worksheets("Example").Unprotect (Password = "0010")
Did anyone encounter this strange phenomenon? Any recommendations?
At the beginning of the procedure you can use
Me.Unprotect("0010")
or you can use
ActiveWorkbook.ActiveSheet.Unprotect("0010")
to use'Your code
at the end of the procedure
Me.Protect ("0010")
or you can
ActiveWorkbook.ActiveSheet.Protect("0010")
to use.Hope I could help you with these information
I know I don't know anything (Socrates)
It should be
Worksheets("Example").Unprotect Password:="0010"
with := between Password and its value.
- esatyilmazCopper ContributorThanks for your help Hans.
- NikolinoDEGold Contributor
At the beginning of the procedure you can use
Me.Unprotect("0010")
or you can use
ActiveWorkbook.ActiveSheet.Unprotect("0010")
to use'Your code
at the end of the procedure
Me.Protect ("0010")
or you can
ActiveWorkbook.ActiveSheet.Protect("0010")
to use.Hope I could help you with these information
I know I don't know anything (Socrates)
- esatyilmazCopper ContributorHi Niko, thank you very much. That worked!