View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
[email protected][_2_] thesquirrel@gmail.com[_2_] is offline
external usenet poster
 
Posts: 39
Default VBA Code and Protection Sheet

What you wrote is exactly what you should do...

Sub Test()
ActiveSheet.Unprotect "password"

'your code here

ActiveSheet.Protect "password"
End Sub

where 'password' is your sheet password

when the sub is run, it will run through from beginning to end first
unprotecting, running your code, then finally reprotecting the sheet.

You can alternatively encompass a single line or any portion of code
with the Unprotect/Protect code we have given you.

Example:

Sub Test()

'beginning of your code

ActiveSheet.Unprotect "password"
Msgbox "just a portion of your code"
ActiveSheet.Protect "password"

'more of your code

End Sub

theSquirrel


amirstal wrote:
Should I put this at the top of the code (just below its name: Sub
EoDProcess())?
"<password" - is where I should write the password that protects the
sheet, right?

Thanks.

wrote:
unlock the worksheet before running the code and lock it back up when
you are done...


Activesheet.Unprotect "<password"

'code here

Activesheet.Protect "<password"





amirstal wrote:
Does Excel have a problem running a VBA code when the worksheet is
protected? If yes, is there a way to overcome it?

Thanks.