test sheet for protection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Been racking my brains again...
Tried:
On Error Resume Next
If Not ActiveSheet.Protection Is Nothing Then
MsgBox "sheet is protected"
Else: MsgBox "Sheet is not protected"
On Error GoTo 0
End If
....but alas, no joy, please help
 
You were nearly there, try this:-

Sub isitprotected()
If ActiveSheet.ProtectContents = True Then
MsgBox ("Protected")
Else
MsgBox ("Unprotected")
End If
End Sub

Mike
 
David,

Check the ProtectContents property:

If ActiveSheet.ProtectContents Then
MsgBox "sheet is protected"
Else
MsgBox "Sheet is not protected"
End If
 
excellent! Thank you

Mike said:
You were nearly there, try this:-

Sub isitprotected()
If ActiveSheet.ProtectContents = True Then
MsgBox ("Protected")
Else
MsgBox ("Unprotected")
End If
End Sub

Mike
 
Excellent! Thank you

Vergel Adriano said:
David,

Check the ProtectContents property:

If ActiveSheet.ProtectContents Then
MsgBox "sheet is protected"
Else
MsgBox "Sheet is not protected"
End If
 
There are different levels of protection...

Option Explicit
sub testme()
msgbox wksisprotected(activesheet)
end sub
Function WksIsProtected(wks As Worksheet) As Boolean
If wks.ProtectContents = True _
Or wks.ProtectDrawingObjects = True _
Or wks.ProtectScenarios = True Then
WksIsProtected = True
Else
WksIsProtected = False
End If
End Function
 
I put this code in the Workbook BeforeClose Event to make sure the Sheet is
protected before I close the App. Works perfectly when I try to close the app
using the Close Button at top right of the window. When I close the App using
the code Application.Quit in a close button I put into a form,
ActiveSheet.ProtectContents is always False. If I use
Sheets("name").ProtectContents, same thing always False.

Does that make sense, is there a work around?
 

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

Back
Top