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?
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?
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.
Found the answer myself:
I need the Workbook.ProtectStructure and Workbook.ProtectWindows properties.
Thanks anyway