How to detect protected sheet

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.
 
G

Gary''s Student

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
 
G

Gord Dibben

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
 
I

IanC

Thanks. I'd tried the ProtectionMode property and couldn't get it to work.
Your solution is just what I needed.
 
I

IanC

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
 

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