View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
BorisS BorisS is offline
external usenet poster
 
Posts: 191
Default code to unprotect sheet with password

Sorry for sounding stupid, but now I am confused.

It sounds like the two pieces I have are how to unprotect with password, and
then how to enable the selection only of unlocked cells. But does the second
piece you gave (the one that enables the selection only of unlocked cells
ALSO protect it, with the same password?

The three steps I need a

1) unprotect (which I think I have from the first response)
some code which I have which will operate in here
2) enabling of selecting only unlocked cells once protected
3) protection with password (use "test" as example)

I have tried to put the following code in (based on what you'd sent, and
what I was guessing would protect it:

ActiveSheet.Unprotect Password = "test"
ActiveSheet.EnableSelection = xlUnlockedCells
ActiveSheet.protect passwords = "test"

and this stops at the first line, which was the one that you'd suggested in
the first message. Am I doing something wrong?
--
Boris


" wrote:

You are right about the password of course - I should have said, having
recorded the macro, use F1 to get help about what you see - but anyway

ActiveSheet.EnableSelection = xlUnlockedCells

should do what you want (I think) - oh, and this bit WAS recorded!


BorisS wrote:
that's always my first try, but it doesn't record the password ones, I
believe. At least I tried it, and it didn't.

One other thing I needed was for it to be specific about only selecting
(2003 version) the ability to select unlocked cells. It usually defaults to
having selection of both locked and unlocked checked. Is there any way to
indicate this in the code?

The code that recorded when I tried this was:
ActiveSheet.protect DrawingObjects:=True, Contents:=True, Scenarios:=True

Thanks for any further help.
--
Boris


" wrote:

You can get this by recording the macro (often a good way to get a look
at possible code choices) but it's

activesheet.unprotect password="fred"
BorisS wrote:
I need to run a macro that first unprotects a password protected sheet, and
then reprotects it later, with a password. The user will not know the
password, and therefore the code needs to, itself, have it hardcoded in
there. I am not concerned about someone digging in the code and finding the
password, so assume that's not an issue.

Is this possible, and if so, what is the code?

Thanks.
--
Boris