View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default How can you create a macro on a protected sheet?

If you set up the protection and the macro, then you know the password?

Option Explicit
sub testme()
dim myPWD as string
myPwd = "hi there"
activesheet.unprotect password:=myPWD
'do your stuff
activesheet.protect password:=mypwd
end sub

======
Depending on what your code does, you could even protect it in code (each time
the workbook opens) and tell excel that you want to allow your macro to do
things that the humans can't.

Option Explicit
Sub auto_open()
With Worksheets("Sheet 99")
.Protect Password:="hi there", userinterfaceonly:=True
End With
End Sub

It needs to be reset each time you open the workbook. (excel doesn't remember
it after closing the workbook.)

But there are a few things that can't be done by your macro--you'll want to test
it to see if it works with the stuff you do.

Felix wrote:

I have a shared worksheet that I have password protected so no one can change
formulas in the cells. I would like to set up macros to provide me with a
certain view for printing and research. Everytime I set up the macro and
protect the sheet it says that I can not use the macro.

Is there anyway around this or will I have to unprotect the sheet everytime
I want to use the macro? Any ideas or suggestions would be greatly
appreciated. Thank you.


--

Dave Peterson