Protect/unprotect sheet with password with VBA?

D

dragontale

All,

I have the following code to protect sheet, then unlock cetain cell
based on the login. So people can onlu modify certain cells. And the
protect the sheet with password, so no one can unprotect the shee
without the password:

ActiveSheet.Unprotect

Range("I4:N6").Select
Selection.Locked = False
Selection.FormulaHidden = False

ActiveSheet.Protect
ActiveSheet.Protect DrawingObjects:=True, Contents:=True
Scenarios:=True
ActiveSheet.Protect Password:="1234567"

But it doesn't work. It ask me for password.

Any suggestion will be appreciated
 
J

JE McGimpsey

Try:

Const PWORD As String = "1234567"
With ActiveSheet
.Unprotect Password:=PWORD
With .Range("I4:N6")
.Locked = False
.FormulaHidden = False
End With
.Protect Password:=PWORD
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top