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 thoughts on “Password Characters

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

  2. 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.

  3. What would you recommend for protection to keep people out?

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

  4. 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.

  5. 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

  6. 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

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

  8. 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.


Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.