• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 540
  • Last Modified:

Why does the ActiveWorkbook.Protect toggle the workbook protection instead of just protecting it?

I find that the line of code in my workbook:

ActiveWorkbook.Protect password '(where "password" is an constant public password)

is actually toggling the workbook protection and not always protecting it no matter what.

Why is this happening and how can I always have it just proteced?
0
HaimD
Asked:
HaimD
  • 2
1 Solution
 
telyni19Commented:
No, the Protect method shouldn't toggle protection; it should always enable it. There is a corresponding Unprotect method to remove the protection.

Are you sure something else isn't removing the protection after you try to enable it?
0
 
HaimDAuthor Commented:
I swore the same thing.  But then I noticed it, and tested it, even on a blank workbook, and indeed, it toggles.

No error message.

I did a work around by always writing the code this way:

ActiveWorkbook.Unprotect
ActiveWorkbook.Protect

Seems ridiculous, but that the way it works.  

Or, maybe someone knows something I don't?!
0
 
Curt LindstromCommented:
You need parameters set to TRUE to avoid this to happen.

Structure Optional Variant True to protect the structure of the workbook (the relative position of the sheets). The default value is False.
Windows Optional Variant True to protect the workbook windows. If this argument is omitted, the windows aren’t protected.

So to protect Structure which is FALSE by default you need to use

ActiveWorkbook.Protect Structure:=True, Windows:=False
or just
ActiveWorkbook.Protect Structure:=True

Regards,
Curt


0
 
HaimDAuthor Commented:
That was it.  Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now