Solved

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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,…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
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…

707 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