Password to activate macro

L

LB79

I have a shared workbook that has a macro i want to protect. Does anyon
know of a way of doing this in either of the following ways:

1. When the macro is activated a MSGBOX asks for a password.

or

2. When the macro is activated it checks the Excel user name and if i
matches the user name in the macro it continues with the macro
otherwise it displays a not authorised message.

Thanks
 
F

Frank Kabel

Hi
pput the following at the beginning of your macro

sub foo()
dim ret
ret = Inputbox ("Enter your password")
if ret <> "your_password" then
msgbox "wrong password"
exit sub
end if

'your code
end sub

BUT: This kind of protection is very weak and can be easily
circumvented by a determined user
 
L

LB79

Fantastic!
Fortunately I am the only person in the office who knows what VB is an
how to use it.

Many thanks
 
Top