[英]Worksheet.Protect doesn't apply a password
I have a workbook which has a macro that copies some data into a second file then tries to protect the resulting worksheet (and workbook) with code along these lines: 我有一个工作簿,该工作簿具有一个宏,该宏将一些数据复制到第二个文件中,然后尝试使用以下几行代码保护生成的工作表(和工作簿):
OutputWb.Sheets("Sheet1").Protect Password:=pw, DrawingObjects:=True, Contents:=True, Scenarios:=True
OutputWb.Protect Password:=pw, Structure:=True, Windows:=False
The issue is, when I then open up the OutputWb
file, I can unprotect both sheet and workbook without it ever asking me for the password. 问题是,当我然后打开OutputWb
文件时,可以取消保护工作表和工作簿,而无需询问密码。
What am I doing wrong, here? 我在做什么错,在这里? Why isn't this working? 为什么这不起作用?
Ah, of course. 嗯当然了
pw
should actually be "pw"
. pw
实际上应该是"pw"
。 It was looking for a variable instead of the string... 它正在寻找变量而不是字符串...
Because I hadn't set Option Explicit
, it wasn't worrying about the fact that the variable has never been declared or anything like that. 因为我没有设置Option Explicit
,所以不必担心变量从未声明过或类似的事实。 :/ :/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.