Open In App

How to Mask Password in VBA Excel Input Box?

Last Updated : 09 Sep, 2025
Comments
Improve
Suggest changes
5 Likes
Like
Report

Passwords are crucial for user authentication in applications, combining letters, numbers, and symbols to verify identity. In Excel VBA, masking passwords (e.g., displaying asterisks instead of characters) prevents unauthorized viewing, such as "shoulder surfing" in public spaces. Unlike the standard InputBox function, which doesn't support masking, a custom UserForm allows secure input.

Steps to Mask Password in VBA Excel Input Box

Follow the further steps to create a masked password in VBA:

Step 1: Press Alt+F11 in the Excel window to get the VBA window. 

Step 2: Select Insert in the Ribbon tab of the VBA code window.

Selecting-insert
Selecting the Insert option from the VBA Ribbon to add a new UserForm.”

Step 3: Then click on UserForm to get the toolbox and user form.

Clicking-on-userform
“Clicking on UserForm to open the toolbox and create the password input form.”

Step 4: Select CommandButton from Toolbox.

selecting-command-button
Choosing the CommandButton control from the Toolbox.”

And then drag it to the UserForm1 tab.

Dragging-to-userform-1-tab
Dragging the CommandButton onto UserForm1 to add a button for submitting the password.”

Step 5: Select TextBox from the toolbox and then drag it to UserForm1.

selecting-testbox
“Adding a TextBox from the Toolbox to UserForm1 for password entry.”

Step 6: Press F4 to get the Properties Window.

Step 7: Change the name of the Text Box to "txtPassword"

Changing-name-of-textbox
Renaming the TextBox control to ‘txtPassword’ in the Properties window.”

Step 8: Change the PasswordChar property of txtPassword to an asterisk (*) to mask the entered password.

Creating-password-mask
Setting the PasswordChar property of txtPassword to an asterisk () to mask the password input.”*

Step 9: In the drop-down box select CommandButton1.

Selecting-commandbutton1
Selecting CommandButton1 to modify its properties.”

Step 10: Change the name of the CommandButton to CmdInput and Caption name to Submit.

Changing-name-of-commandbutton
Changing CommandButton’s name to ‘CmdInput’ and its caption to ‘Submit’.”

Step 11: Change the caption name in the Properties - UserForm1 tab to Password.

changing-caption-name
“Changing the caption of UserForm1 to ‘Password’ for clarity.”

Step 11: Double-click on Submit button of the Password form.

Clicking-submit
Click on the Submit Button

Step 12: Unload Me is used to close the form and remove its details from memory Now, to run the code press F5.

Step 13: Enter your password, which will stay hidden in the UserForm window.

entering-password
“Testing the form by entering a password, which remains hidden due to the masking.”

Step 14: Click the Submit button to display the password in a message box.

Clicking-submit
Clicking the Submit button to display the password in a message box.”

Explore