?
Solved

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

Posted on 2010-09-17
4
Medium Priority
?
526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

650 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