Password Characters

You know how when you type your password in most programs it’s masked? That’s good. You don’t want your co-workers peering over your shoulder and messing with your eBay account. Well, you can do the same thing in VBA. Specifically, using Textboxes on Userforms. The Textbox control has a PasswordChar property which you can set to any character you’d want, like *.

PassChar1

Now when the user types in the Textbox, the text is masked.

PassChar2

Unfortunately, the InputBox method and function don’t have this property. You have to make a Userform to use it.

10 Comments

  1. Juan Pablo says:

    I like this solution:

    http://www.danielklann.com/excel/hiding_text_in_a_vba_inputbox.htm

    just because it shows that you *can* do it with an InputBox… of course, using the Userform may be easier to implement !

  2. Dick says:

    Good one, Juan. I remembered that I had seen that before when I went there because he uses my initials in his function.

  3. JWalk says:

    Keep in mind that in order to use something like this, the password needs to be stored somewhere in a VBA module. And we all know that the protection for VBA modules is very weak. In other words, using a password provides absolutely no guarantee that you will keep out the people you want to keep out.

  4. Stac says:

    What would you recommend for protection to keep people out?

    Or, letting them view, but not change the information?

  5. Andy Miller says:

    Stac, for 98% of users’ applications, simply protecting an Excel file with a password (and possibly hiding and protecting the VBA code) would be sufficient. The passwords can be cracked with some 3rd party software applications, but if you need true unbreakable protection, then perhaps straight Excel would not be the way to go.

  6. Stac says:

    Andy–

    Thanks for the confirmation. It is as I suspected. My company is reeling from some implications of Sarbanes-Oxley and our usage of Excel sheets.

    Not sure how we are going to proceed, but considering the number of Excel sites I’ve checked this fact on, our practices will have to change.

    stac

  7. Stac says:

    Andy–

    Thanks for the confirmation. It is as I suspected. My company is reeling from some implications of Sarbaines-Oxley and our usage of Excel sheets.

    Not sure we are going to proceed, but considering the number of Excel sites I’ve checked this fact on, our practices will have to change.

    stac

  8. Dedy says:

    thanks for the explanation. it’s so usefull….

  9. Alex J says:

    JWalk,
    I typically keep passwords saved in a Named Range (not on a sheet). If this range is hidden, would it change your opinion?

  10. Jon Peltier says:

    Alex -

    A hidden name is much easier to unhide than a protected VB project is to unprotect.

    For Each nm In ActiveWorkbook.Names
    nm.Visible = True
    Next

    Now you can see it in the Define Names dialog. To unprotect a VB project which has an unknown password, you have to hack into the file using a hex editor.

Leave a Reply