Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I detect the protection status of worksheet in VBA 1

Status
Not open for further replies.

bkh

Technical User
May 18, 2001
5
EU
Can anyone help.
If possible I would like to be able to detect if a worksheet in Excel97 is protected or unprotected so that a macro (vba subroutine) can unprotect if needed without user intervention and then protect after running.
Thanks
 
Is this what you are looking for?
Code:
Sub test()
    Dim ws As Worksheet
    Set ws = Sheets("Sheet2")
    If ws.ProtectContents = True Then
        MsgBox "The contents of Sheet2 is protected."
        ws.Unprotect
    Else
        MsgBox "The contents of Sheet2 is unprotected."
    End If
    Set ws = Nothing
End Sub
 
Thanks dsi, that was exactly what I was looking for. It works fine. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top