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

Ensuring Standardized Numbering

Want to make sure your paragraph numbering looks the same on different computer systems? It's a harder task in Word than ...

Discover More

Sorting an Album List

Word allows you to easily sort the information you store in a document. If you want to sort information as groups of ...

Discover More

Automatic Sound Clips

Want to add some sound to your documents? It's easy. What isn't so easy is configuring a sound clip to play whenever a ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (menu)

Automatically Changing References to VBA Libraries

VBA libraries are used to provide some functions to your macros. These libraries are often tied to the version of Excel ...

Discover More

Assigning a Macro to a Keyboard Combination

Macros are a great way to expand what you can do with the data you place in Excel. You can make those macros even handier ...

Discover More

Using Named Ranges in a Macro

Named ranges are a great capability provided by Excel. You can define all sorts of named ranges in a workbook, but how do ...

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 1 + 1?

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.