Protect/unprotect sheet with password with VBA?

  • Thread starter Thread starter dragontale
  • Start date Start date
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
 
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
 
Back
Top