How to detect protected sheet

  • Thread starter Thread starter IanC
  • Start date Start date
I

IanC

How do I detect whther a sheet is protected or not? I need the sheet
unprotected for the subroutine, but I need to know whether it was already
unprotected so I can leave it in the same satte after the sub runs.
 
Do it the type of item being protected:

Sub dural()
Dim s As Worksheet
Dim t As Boolean
Set s = ActiveSheet
t = s.ProtectContents
MsgBox (t)
End Sub
 
Directly from VBA help on ProtectContents Property

If Worksheets("Sheet1").ProtectContents = True Then
MsgBox "The contents of Sheet1 are protected."
End If


Gord Dibben MS Excel MVP
 
Thanks. I'd tried the ProtectionMode property and couldn't get it to work.
Your solution is just what I needed.
 
Gord Dibben said:
Directly from VBA help on ProtectContents Property

If Worksheets("Sheet1").ProtectContents = True Then
MsgBox "The contents of Sheet1 are protected."
End If

Thanks Gord. I looked at this after Gary's Student pointed me this way. It's
easy when you know what keywords to look for. I'd searched for "Protect" and
ProtectionMode sounded the most likely....

.....but wasn't
 
Back
Top