VBA code - protect and unprotect a sheet

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

Can someone please provide code to protect and unprotect a
sheet. Assume sheet name is "Sam" and password
is "Malone". Thanks.
 
Jeff said:
Can someone please provide code to protect and unprotect a
sheet. Assume sheet name is "Sam" and password
is "Malone". Thanks.

Sheets("Sam").Unprotect password:="Malone"
Sheets("Sam").protect password:="Malone"
 
Sub Protect()

Sheets("Sam").Protect Password:="Malone"
End Sub

---------------------------------------------

Sub UnProtect()

Sheets("Sam").UnProtect Password:="Malone"
End Sub

---------------------------------------------

If you just want a routine to toggle it, then the following from JE McGimpsey
will do that:-

Sub ToggleProtect()

Const PW As String = "Malone"

With Sheets("Sam")
If .ProtectContents = False Then
.Protect PW
Else
.UnProtect PW
End If
End With

End Sub
 
I am a novice in creating Excel VBA codes. With the code provided here, I am very successful in creating a sheet in which I needed the Macros to work in a protected sheet.

Thanks to Ken Wright and Gerrit

Regards,
G.Manikandan
 
Back
Top