VBA "IF" True/False test for ActiveSheet Protection

D

Dennis

Using XL 2003

First, After successfully running a macro, my WS ends up being protected.

I cannot understand why that happens as, in this particular Sub Routine, there is no
command applying protection.

Yes, I can add to my current macro:

ActiveSheet.Unprotect

and that works! But why does it become protected in the first place?


Because of the above, I would like to "test" for protection status.

If WS protection is True, then I want to apply:
Active.Sheet.Protect UserInterfaceOnly:=True

so that the Macro will complete
I tried:
If ActiveSheet.Protect = True
but it does not seem to do what I want.


Then I wish to leave the WS protection exactly as it was before the macro was run.

TIA Dennis
 
F

Frank Kabel

Hi Dennis
Protect is a method and not a property. So your If statement protect
the worksheet. Try the following instead

If ActiveSheet.ProtectContents = True
.....
 
D

Dennis

Hello Frank!

I checked the WS protection status as "none" before the macro.

What would cause a WS to become protected if it were not before a macro and if there
were no statement in the macro applying protection?

Thanks to the code info!
 
F

Frank Kabel

Hi Dennis
the statement
If ActiveSheet.Protect = True then...

in your current code will NOT check the current protection status of
your worksheet BUT will protect it!
 
D

Dennis

Oh well, I screwed up.

In my macro, I called another macro that did have a protection command.

It is amazing how easy it is to keep walking the same blind path.

Thanks Frank!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top