protect/unprotect worksheet

G

Guest

I'm trying to use a button to protect/unprotect a sheet. But, I'm not sure
what I should use in the If statement to identify whether the sheet is
protected or not.
Private Sub cmdProtect_Click()
With ActiveSheet
If ActiveSheet.ProtectionMode Then ' not working, it's always True
.Unprotect Password:="password"
cmdProtect.BackColor = &HFFFF00
cmdProtect.Caption = "UnProtected"
Else
.Protect Password:="password", _
Contents:=True, UserInterfaceOnly:=True
cmdProtect.BackColor = &HFF&
cmdProtect.Caption = "Protected"
End If
End With
End Sub

Can anybody help?

Thanks
 
G

Guest

ProtectContents is probably what you are looking for.

if activesheet.protectcontents then
 

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

Top