Link to home
Start Free TrialLog in
Avatar of Maliki Hassani
Maliki HassaniFlag for United States of America

asked on

Excel: Masking password in VBA

Experts:

I am looking to add a masking over the password that a person is typing in the input box.  Currently, my code shows the code..  Any ideas on where to look?
Avatar of Peter Kwan
Peter Kwan
Flag of Hong Kong image

Do you require a macro for your masking? If no, you may consider setting "PasswordChar" for the Textbox Properties.

To do this:

1) right click your input box, and click "Properties".
2) In the "Properties" window, you should see "PasswordChar". Just put a character there.
Here's a good tip I contributed to recently.  Several options, though I like mine the best :).  It might do the trick.

https://www.experts-exchange.com/questions/26818311/Password-Mask-in-INPUT-BOX-for-VBA.html

dave
ASKER CERTIFIED SOLUTION
Avatar of dlmille
dlmille
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
LANCE_S_P,

Try the attached file - code below.

If in the Userform you select the TextBox and look at its Properties you will see that the Password character has been set to *. That means that whenever you press a key only an asterix will be shown in the TextBox. When you press the 'Use password' button it checks whether you have entered the correct password. If the password is correct the Userform will be hidden and unloaded.

In practice you of course need to lock the VBA project so that people cannot just read the VBA code to find out what the password is.

Patrick
Private Sub CommandButton1_Click()
If LCase(Me.TextBox1.Text) = "qwerty" Then
    MsgBox "Password was correct"
    Me.Hide
    Unload Me
Else
    MsgBox "Password was incorrect"
End If
End Sub

Open in new window

password-masking-01.xls
Avatar of Maliki Hassani

ASKER

This was what I was looking for. Hackers are out there, this works best in vba..  Thanks
LANCE_S_P,

>Hackers are out there, this works best in vba..

My solution only works in VBA!

Patrick