简体   繁体   English

Excel-VBA检查工作表是否不受保护

[英]Excel - VBA Check if worksheet is unprotected

With if Worksheets("test").ProtectContents I can recognize if the worksheet is protected. 使用if Worksheets("test").ProtectContents可以识别工作表是否受保护。 It only returns a true, right? 它只返回一个真值,对吗?

How can I check if it is unprotected? 如何检查它是否不受保护?

If Worksheets("test").ProtectContents = True Then: Exit Sub:

For Each cell In Range("B6:B112")
...
Next cell

Else:

If Not Worksheets("test").ProtectContents Then
Dim rng As Range
...

The foreach loop have to execute when the sheet is protected. 在保护工作表时必须执行foreach循环。 And the part at if not worksheet.. is for the part when the sheet is unproteced. 如果不是工作表,则该零件用于未保护工作表的零件。 thx. 谢谢。

I guess this is what you are looking for, 我想这就是你想要的,

If ActiveSheet.ProtectContents = True Then
MsgBox "Protected"
Else
MsgBox "Not protected"
End If

if not, please comment. 如果没有,请发表评论。 hopefully we shall able to resolve your issue. 希望我们能够解决您的问题。

尝试这样:

If Not Worksheets("test").ProtectContents Then Exit Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM