How to tell if an Excel Workbook is protected
-
02-07-2019 - |
Question
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?
Solution
Found the answer myself:
I need the Workbook.ProtectStructure
and Workbook.ProtectWindows
properties.
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow