Password Protected Macro code (VBA) in Excel

hbui

New Member
Joined
Jul 26, 2005
Messages
5
I know how to password protect an excel workbook but when you add a MACRO to the workbook...how do you put a password on it?

Thanks in advance.
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Macropheliac

Board Regular
Joined
Aug 26, 2005
Messages
165
Try this:

Code:
Sub Password_Code()
If Not InputBox("Password") = "Your Password Here" Then Exit Sub
'Rest of code Here
End Sub
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Welcome to the Board!

In the VBE you can goto Tools-->VBA Project Properties-->Protection-->Lock project from vieving-->Add password (2x).

HTH,

Smitty
 

Watch MrExcel Video

Forum statistics

Threads
1,113,916
Messages
5,545,020
Members
410,646
Latest member
LegenDSlayeR
Top