I can use properties of an Excel Worksheet to tell if the worksheet is protected (Worksheet.Protection, Worksheet.ProtectContents etc).
我可以使用Excel工作表的属性来判断工作表是否受到保护(Worksheet.Protection,Worksheet.ProtectContents等)。
How can I tell using VBA if the entire workbook has been protected?
如果整个工作簿受到保护,如何使用VBA告诉我?
2 个解决方案
#1
4
Found the answer myself:
自己找到了答案:
I need the Workbook.ProtectStructure
and Workbook.ProtectWindows
properties.
我需要Workbook.ProtectStructure和Workbook.ProtectWindows属性。
#2
2
Worksheet.ProtectedContents is what you would need to use, on each Worksheet.
您需要在每个工作表上使用Worksheet.ProtectedContents。
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.
如果每个工作表都受到保护,该函数将返回True,如果有任何工作表未受保护,则返回False。我希望这就是你要找的东西。
#1
4
Found the answer myself:
自己找到了答案:
I need the Workbook.ProtectStructure
and Workbook.ProtectWindows
properties.
我需要Workbook.ProtectStructure和Workbook.ProtectWindows属性。
#2
2
Worksheet.ProtectedContents is what you would need to use, on each Worksheet.
您需要在每个工作表上使用Worksheet.ProtectedContents。
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.
如果每个工作表都受到保护,该函数将返回True,如果有任何工作表未受保护,则返回False。我希望这就是你要找的东西。