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.
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.
Learn more about Allen...
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.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3120) applies to Microsoft Excel 97, 2000, 2002, and 2003.
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!