PDA

View Full Version : Solved: Protecting Sheets With a Password



zoom38
07-20-2006, 07:25 PM
I use the sub below that mdmackillop created to protect and unprotect my sheets so code will run. Now I want to password protect the sheets. If I protect the sheet with "pword" as my password and then activate the sub below, it works fine, it unprotects the sheets using the password. The problem lies when the sub protects the sheets, it will not protect the sheets with a password. I want the sheets to be password protected all of the time. I can't figure it out. Any ideas?


Sub DoProtect(x As Boolean)
For Each Sh In Worksheets
If x = False Then Sh.Unprotect password:="pword"
If x = True Then Sh.Protect password:="pword"
Next
End Sub


Thanks
Gary

acw
07-20-2006, 10:30 PM
Gary

Worked for me. Protected the sheets and I could unprotect manually using pword.....


Tony

zoom38
07-21-2006, 06:04 AM
Hello again Tony, my mistake. My sub calls another sub that unlocks the sheets and does not password protect. I threw on the password and it works. Thanks for loooking at it.

Gary