Unprotecting worksheet through VB macro


Posted by Marc on January 04, 2002 8:45 AM

Would anyone know how to create a VB macro that would take a protected worksheet and unprotect it? Meaning, when the user opens the workbook, a sheet would be protected until you clicked on a command button that would unprotect it. I can't seem to find the correct order for this to happen and Excel's minimal VB programming language does show that it supports unprotecting. Thanks for any help anyone can give!

Posted by Scott on January 04, 2002 9:40 AM

The best way to do this is to record a macro where you protect, the sheet, and then unprotect. You can do this in seperate macros if you'd like. Then just assign each macro to a button.



Posted by DonnaW on January 04, 2002 9:40 AM

To protect use: ActiveSheet.Protect Password:="PSWord"

To unprotect use: ActiveSheet.Unprotect Password:="PASSWORD"

Of course, if you need to make sure the active sheet is the one you want to protect. Also, if anyone knows how to look at the VB code, they would be able to find out the password.