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.
What am I doing wrong, 开发者_开发技巧here? Why isn't this working?
Ah, of course.
pw
should actually be "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. :/
精彩评论