Excel Macro; Adding Password [Solved/Closed]

Ask a question zeromaim 10Posts Monday July 28, 2008Registration date August 8, 2008 Last seen - Last answered on Mar 13, 2013 at 10:39 AM by Pujdo

Hope you anyone can help me with this...

I need to create a macro that unlocks a password-protected sheet with password "password", do some instruction, then locks it again with same password.

Thanks in advance for any assistance.

plus moins
Hello zero,
the syntax is quite simple
ActiveSheet.Unprotect ("MyPassWord")
ActiveSheet.Protect ("MyPassWord")

for more details, I suggest you type "worksheet.protect" and "worksheet.unprotect" in the help file of visual basic editor.
Was this answer helpful?  
zeromaim 10Posts Monday July 28, 2008Registration date August 8, 2008 Last seen - Aug 6, 2008 at 07:22 AM
Hi Ivan,

Thanks for this, and other one as well.
I'm not actually a programer. I self-studied excel and i'm good at using formulas.
I just recently learn about macro and I used to just for recording to eliminate the circular ref error with formulas.
I was glad to have found this site and have read one of your response.


DaveyBoy- Oct 7, 2008 at 12:29 PM
The ActiveSheet.Protect ("MyPassWord") works, but what if you want the set certain "abilities" to True when assigning the password as in the following code.

ActiveSheet.Protect ("MyPassWord") DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True

This errors out when the Macro is ran. Is there a different Syntax for a case like this?
Ivan-hoe 436Posts dimanche 17 février 2008Registration date October 17, 2008 Last seen - Oct 8, 2008 at 06:46 AM
try this syntax :
ActiveSheet.Protect PassWord:="MyPassWord", DrawingObjects:=True,  _ 
Contents:=True,  Scenarios:=True, AllowSorting:=True, AllowFiltering:=True,  _ 

Josh- Sep 9, 2009 at 07:12 AM
Hey Ivan valuable info on your post. Thanks pal.
Abbi- Sep 17, 2010 at 01:28 AM
thanks Ivan...ur post was a real help :)
plus moins
Thanks Ivan.

How do I change the status of this topic to "resolved"?

aquarelle 7180Posts Saturday April 7, 2007Registration date ModeratorStatus July 27, 2017 Last seen - Aug 8, 2008 at 03:30 PM
Go to the top of your thread (to the right part), and check the case "solved" after click on "OK"
Best regards
plus moins
Thanks Ivan!
Ram's- Jul 28, 2010 at 08:23 AM
i want those number in front add ''0" (Zero) how to 456789
rizvisa1 4482Posts Thursday January 28, 2010Registration date ContributorStatus January 6, 2016 Last seen - Jul 28, 2010 at 10:14 AM
Ram: what this question "i want those number in front add ''0" (Zero) how to 456789 11111 22222 33333", has to do with the thread ?
plus moins
how to remove the xsl sheet password
plus moins
Tnx for this :) this is working for me :)

Member requests are more likely to be responded to.

Members can monitor the statuses of their requests from their account pages.

A CCM membership gives you access to additional options.

Not a member yet?

Sign up now. It takes less than a minute and is completely free!