PDA

Click to See Complete Forum and Search --> : Passwording a Macro


daved2424
Feb 17th, 2004, 10:57 AM
How do I assign a password to a macro? I.e. before you run the macro you must enter a password.

Is it difficult to manage/change/update etc?

Many Thanks

Yesuslave
Feb 17th, 2004, 01:27 PM
This is very easy

Just create a variable called strPassword. Assign it a value like "mywords" and then have a message box pop up at the beginning of the macro. If the password they enter does not match your strPassword variable, the macro quits. if not, it runs. Of course, if someone opens your macro to view the code, they will be able to see your password.

Josh

salvelinus
Feb 17th, 2004, 01:52 PM
Better yet, stay away from macros.

TheFIDDLER
Feb 19th, 2004, 09:37 PM
Lock your project with a VBA password so that they cannot can into your code and glance easily at the macro password.
(VBA menu, Under tools, VBA Project Properties, Lock Project for Viewing)


As for the password itself, quite simple.

Dim x as string
x = "password"
display = inputbox("Please enter password")
if display <> x then exit sub
... rest of code

Note, be creative, using password as a password is lame.

As to maintenance, just edit the code and change the value you assign to X.