Solved

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

Posted on 2010-09-17
4
498 Views
Last Modified: 2012-06-27
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
Comment
Question by:HaimD
  • 2
4 Comments
 
LVL 12

Expert Comment

by:telyni19
ID: 33704547
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
 

Author Comment

by:HaimD
ID: 33704747
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
 
LVL 18

Accepted Solution

by:
Curt Lindstrom earned 500 total points
ID: 33707434
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
 

Author Closing Comment

by:HaimD
ID: 33716832
That was it.  Thanks
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question