How to determine if an Excel workbook is protected

I can use the properties of the Excel worksheet to find out if the worksheet is protected (Worksheet.Protection, Worksheet.ProtectContents, etc.).

How can I find out using VBA if the entire workbook is protected?

+4
source share
2 answers

Found the answer myself:

I need the properties of Workbook.ProtectStructure and Workbook.ProtectWindows .

+4
source

Worksheet.ProtectedContents is what you will need to use on each sheet.

So, I would create 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 each sheet is protected, and False if any worksheets are not protected. Hope this is what you were looking for.

+2
source

Source: https://habr.com/ru/post/1277077/


All Articles