vba 如何判断 Excel 工作簿是否受保护
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/121808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to tell if an Excel Workbook is protected
提问by Joe
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 判断整个工作簿是否受到保护?
回答by Joe
Found the answer myself:
自己找到了答案:
I need the Workbook.ProtectStructure
and Workbook.ProtectWindows
properties.
我需要Workbook.ProtectStructure
和Workbook.ProtectWindows
属性。
回答by Guy Starbuck
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。我希望这就是你要找的。