Is this worksheet protected?

  • Thread starter Thread starter ianripping
  • Start date Start date
I

ianripping

Is there a formula or VBA command that can determine is a sheet i
protected or not
 
here is one way

Sub test()
If ActiveSheet.ProtectContents Then
MsgBox "This sheet is protected"
Else
MsgBox "This sheet is unprotected"
End If

End Sub

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2000 & 97
** remove news from my email address to reply by email **
 
Excellent. Thanks to all who posted. I came up with this......

Sub Master()
If ActiveSheet.ProtectContents Then
On Error Resume Next
Dim strWrongPasswordMsg As String
Do
Pwd = InputBox(strWrongPasswordMsg & "Please enter password t
unprotect this sheet....")
If Pwd = "" Then
Cancel = True
Exit Do
Else
Err.Clear
Sheets("AOct").Unprotect Pwd
If Err.Number = 0 Then
Exit Do
End If
strWrongPasswordMsg = "Invalid password." & vbCrLf & vbCrLf
End If
Loop
Else
If Pwd <> "" Then
Sheets("AOct").Protect Pwd
MsgBox "Worksheet is now protected. Thankyou"
End If
End If
End Sub

With your help of course
 
That only checks for contents protected, not scenarios or objects, so it is
not catch-all.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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