Password protect a macro

  • Thread starter Thread starter Crownman
  • Start date Start date
C

Crownman

Hello -

I have a workbook that contains several macros that I want only some
of the users to be able to run. Is there some way that I can add code
to these macros that will require the user to enter a password in
order to get the macro to run? Or is there some other way to
accomplish this?

TIA for any advice.

Crownman
 
If the other users don't know the names of the macros you could lock the project
for viewing with a password.

Then "some users" could just enter the name of the macro in the dialog box at
Tools>Macro>Macros and run from there.

Or unlock the project to get a list of the macros to run.

As a back-up to the above you could code to password the macro from running.

Sub do_things()
Const pword As String = "secret"
permit = InputBox("Enter the secret word")
permit <> pword Then
MsgBox "not today, Wilbur"
Exit Sub
End If
MsgBox "you got it right"
End Sub

You would also have to lock project for viewing so's no unathorized user could
see the secret password.


Gord Dibben MS Excel MVP
 
To protect the password from being seen, you can create a userform with a
TextBox and specify "*" as the password character for the TextBox. When the
person types in the password, all tha apprears are *'s.

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel
 
To protect the password from being seen, you can create a userform with a
TextBox and specify "*" as the password character for the TextBox.  Whenthe
person types in the password, all tha apprears are *'s.

Bob Flanagan
Macro Systemshttp://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel









- Show quoted text -

Thank you both for your advice. I figured out a workable solution by
making the macros Private Subs. This hid them from the selection box
from Tools>Macro>Macro. Then hiding the code from viewing will keep
unauthorized users from viewing the code. I just have to make sure
that the authorized users know the macro names.

Crownman
 
After you add the top secret password check to each macro, you could give the
users an easier way to run them.

For additions to the worksheet menu bar, I really like the way John Walkenbach
does it in his menumaker workbook:
http://j-walk.com/ss/excel/tips/tip53.htm

Here's how I do it when I want a toolbar:
http://www.contextures.com/xlToolbar02.html
(from Debra Dalgleish's site)

And if you use xl2007:

If you want to learn about modifying the ribbon, you can start at Ron de Bruin's
site:
http://www.rondebruin.nl/ribbon.htm
http://www.rondebruin.nl/qat.htm -- For macros for all workbooks (saved as an
addin)
or
http://www.rondebruin.nl/2007addin.htm

In xl2007, those toolbars and menu modifications will show up under the addins.
 
Back
Top