Solved

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

Posted on 2010-09-17
4
491 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now