Reputation: 124696
I can use properties of an Excel Worksheet to tell if the worksheet is protected (Worksheet.Protection, Worksheet.ProtectContents etc).
How can I tell using VBA if the entire workbook has been protected?
Upvotes: 4
Views: 7270
Reputation: 124696
Found the answer myself:
I need the Workbook.ProtectStructure
and Workbook.ProtectWindows
properties.
Upvotes: 5
Reputation: 21873
Worksheet.ProtectedContents is what you would need to use, on each Worksheet.
So I would set up a loop like this:
Public Function wbAllSheetsProtected(wbTarget As Workbook) As Boolean
Dim ws As Worksheet
wbAllSheetsProtected = True
For Each ws In wbTarget.Worksheets
If ws.ProtectContents = False Then
wbAllProtected = False
Exit Function
End If
Next ws
End Function
The function will return True if every worksheet is protected, and False if there are any worksheets not protected. I hope this is what you were looking for.
Upvotes: 2