How to Mask Password in VBA Excel Input Box?
Last Updated :
09 Sep, 2025
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.
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 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 to open the toolbox and create the password input form.”Step 4: Select CommandButton from Toolbox.
Choosing the CommandButton control from the Toolbox.”And then drag it to the UserForm1 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.
“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"
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.
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 to modify its properties.”Step 10: Change the name of the CommandButton to CmdInput and Caption name to Submit.
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 the caption of UserForm1 to ‘Password’ for clarity.”Step 11: Double-click on Submit button of the Password form.
Click on the Submit ButtonStep 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.
“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 the Submit button to display the password in a message box.”
Explore
Excel Fundamental
Excel Formatting
Excel Formula & Function
Excel Data Analysis & Visualization
Advanced Excel
Excel Data Visualization
Excel VBA & Macros
Power BI & Advance Features in Excel