Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can not run a Macro on an Excel protected sheet

Status
Not open for further replies.

mimitan

Technical User
Dec 17, 2004
34
Hello everyone.
I have a workseet that has a command button that trigger a macro. When the seet is not protected I can press the command button and the macro run fine (autofilter) but when the sheet is protected from others to modify, it give a runtime error when pressing the command button. Is there a way aroud to protect my sheet and at the same time allow me to run the autofilter macro?
Thanks for Help
 
Just insert VBA to unprotect the sheet at the beginning of your code, and to reprotect it at the end. . .

There is also a way to protect a sheet using VBA so that users can't change it, but code can.

VBAjedi [swords]
 
But that has to be implemented every time the workbook opens as it is turned off whenever the file is closed...

Rgds, Geoff

"Three things are certain: Death, taxes and lost data. Guess which has occurred"

Please read FAQ222-2244 before you ask a question
 
Thanks VBAJedi.
I recorded the macro to protect and unprotect the sheet and inserted the VBA in my command button. When I try to press the command button it ask me a password to unprotect the sheet. Can I include a password in the VBA in the protect and unprotect codes so that when I press the button it will unprotect? if yes, how?
Thanks.
 
Yes, you can include a password. Examples of both approaches can be found in thread707-666161 .

Incidentally, reading that thread would have saved you the trouble of posting at all. . . it's a good example of how it can pay off to search the forums past threads first! But I know you're new here, and I don't mind helping you with that.

VBAjedi [swords]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top