![]() |
code to unprotect sheet with password
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 |
code to unprotect sheet with password
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 |
code to unprotect sheet with password
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 |
code to unprotect sheet with password
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 |
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 |
code to unprotect sheet with password
I must admit I was a bit confused with the order of what I'd recorded,
as the selection of unlocked only cells was set AFTER the password - having done a quick test, it doesn't matter which way round it's run - each line is independant and the password setting bit will set the password, the unlocked cells only being selected bit will allow only unlocked cells to be selected! You do need BOTH lines though. BorisS wrote: 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 |
code to unprotect sheet with password
thanks for the clarification. I am still confused as to what I typed
incorreclty, that made the code not run from the first line that you'd given me. What am I missing/erring on in my block of code? Thx. -- Boris " wrote: I must admit I was a bit confused with the order of what I'd recorded, as the selection of unlocked only cells was set AFTER the password - having done a quick test, it doesn't matter which way round it's run - each line is independant and the password setting bit will set the password, the unlocked cells only being selected bit will allow only unlocked cells to be selected! You do need BOTH lines though. BorisS wrote: 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 |
code to unprotect sheet with password
That did it. Thanks.
-- Boris "BeeGee" wrote: BorisS wrote: thanks for the clarification. I am still confused as to what I typed incorreclty, that made the code not run from the first line that you'd given me. What am I missing/erring on in my block of code? Thx. -- Boris " wrote: I must admit I was a bit confused with the order of what I'd recorded, as the selection of unlocked only cells was set AFTER the password - having done a quick test, it doesn't matter which way round it's run - each line is independant and the password setting bit will set the password, the unlocked cells only being selected bit will allow only unlocked cells to be selected! You do need BOTH lines though. BorisS wrote: 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 Greetings: Add colons immediately after the word Password ie: activesheet.unprotect password:="fred" Hope this helps |
All times are GMT +1. The time now is 12:11 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com