Hiding Entries in an InputBox

Written by Allen Wyatt (last updated September 3, 2022)
This tip applies to Excel 97, 2000, 2002, and 2003


Andrew is writing a macro, and he wants to give users the opportunity to enter their password prior to permitting them to use certain functions provided by the macro. He is using the InputBox function, and wonders if there is a way to "strike out" whatever someone enters, so the password is kept private as it is typed. (This is done in many programs, where whatever is typed is replaced on-screen with asterisks or some other character.)

There is no direct way to do this using the InputBox function; it doesn't include the needed functionality. There are folks who have done it using API calls and the like, but that gets rather involved and—in all likelihood—beyond the scope of ExcelTips.

An easier approach is to create your own UserForm in VBA. The form can contain a TextBox, and the control includes a property you can set to function as a masking character when someone enters a password. If you display the property window for the TextBox control, you'll see a property named PasswordChar. Set this to whatever character you want used for the masking. For instance, you could put a single asterisk in the property.

When it comes time to check whether the user entered the correct password, then all you need to do is check the value in the TextBox control; it will be "clear" (unmasked), while the on-screen version remains masked. In other words, if someone enters "MyPass" as their password, then that is the value associated with the control itself. However, what shows on the screen is six asterisks (or whatever masking character you specified), one for each letter typed.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3120) applies to Microsoft Excel 97, 2000, 2002, and 2003.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Finding Text Boxes

Need to search for various text boxes in your document? It's easy to do with the handy macro provided in this tip.

Discover More

Symbols for Non-Printing Characters

Displaying non-printing characters can help you better understand the formatting and contents of your documents. What do ...

Discover More

Tools to Boost Motivation and Productivity

Sometimes a writer needs motivation to keep ploughing ahead in their craft. Word doesn't really include any tools to help ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (menu)

Copying Worksheets in a Macro

Copying worksheets (one or many) is easy to do manually. What is not well known is that it is even easy to make the ...

Discover More

Maximum Length Limit for a Macro

Make your macros too long, and Excel may just refuse to run them at all. This tip explains what the limit is for macros, ...

Discover More

Writing a Macro from Scratch

Recording macros is a great approach to getting started with macros, but at some point you'll need to create one from ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four minus 0?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.