Excel 工作表。调用工作表后,保护内容默认为FALSE。保护两次
Excel 工作表。调用工作表后,保护内容默认为FALSE。保护两次,excel,vba,Excel,Vba,工作表.Protect的Contents参数默认为TRUE。调试代码时,我发现ProtectContents属性在Worksheet时变为FALSE。在某些情况下,在已受保护的工作表上再次调用Protect。我不明白为什么;这是一种期望的行为吗 以下是我使用的代码: Sheets(1).Protect _ Userinterfaceonly:=True, _ DrawingObjects:=False, _ Password:=MyPassword ' calling t
工作表.Protect的Contents
参数默认为TRUE
。调试代码时,我发现ProtectContents
属性在Worksheet时变为FALSE
。在某些情况下,在已受保护的工作表上再次调用Protect
。我不明白为什么;这是一种期望的行为吗
以下是我使用的代码:
Sheets(1).Protect _
Userinterfaceonly:=True, _
DrawingObjects:=False, _
Password:=MyPassword
' calling twice => ProtectContents falls to FALSE !
如果我省略了DrawingObjects
参数,则调用代码两次后,protectcontents
仍保持TRUE
:
Sheets(1).Protect _
Userinterfaceonly:=True, _
Password:=MyPassword
' calling twice => ProtectContents remains TRUE
=>如果在已受保护的工作表上调用Protect
方法并给出任何参数,则该行为与在未受保护的工作表上调用Protect
不同
我的解决方案是显式添加内容:=True
:
Sheets(1).Protect _
Contents:=True, _
Userinterfaceonly:=True, _
DrawingObjects:=False, _
Password:=MyPassword
' calling twice => ProtectContents remains TRUE as stated
因此,我已经知道如何让我的代码工作,但我想清楚地了解原因