Code to protect/unprotect a sheet using a macro with password
"Paul B" wrote:
FredH, something like this,
Const PW As String = "123" 'Change Password Here
ActiveSheet.Unprotect Password:=PW
'you code here
ActiveSheet.Protect Password:=PW
And protect the VBA project so they can't see the password there, like this
To protect the VBA project, from your workbook right-click the workbook's
icon and pick View Code. This icon is at the top-left of the spreadsheet
this will open the VBA editor, in Project Explorer right click on your
workbook name, if you don't see it press CTRL + r to open the Project
Explorer then select VBA project properties, protection, check lock project
for viewing and set a password. Press Alt and Q to close this window and go
back to your workbook and save and close the file. Be aware that this
password can be broken by third party software
"FredH" wrote in message
...
I have a worksheet that I created that requires a lot of sorting and other
macros. However with the worksheet protected I can't perform the
functions. I
need the worksheet password protected so the user can't mess up the
formulas.
Therefore, I need to un-protect the worksheet, sort the rows and then
re-protect the worksheet. I can do it if I give the user the password but
then they can just un-protect it. Therefore I want to have the password in
the macro so it is done automatically. Help!
The following are my two macros. I don't have any sort codes in them. The protect macro puts the password test in but the unprotect macro doesn't work.
|