tags:

views:

645

answers:

2

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?

A: 

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.

Guy Starbuck
Thanks, but this isn't what I'm looking for. All worksheets can be protected without the workbook being protected. I need the workbook to be protected so that the user can't unhide hidden sheets. I found the answer myself: Workbook.ProtectStructure and Workbook.ProtectWindows.
Joe
+1  A: 

Found the answer myself:

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

Thanks anyway

Joe