Open In App

How to Mask Password in VBA Excel Input Box?

A combination of integers, strings of characters, or other symbols is used to verify the identity of a user during the authentication process so, that they can access the system. But a password should always remain in a hidden format to prevent it from shoulder spying. Shoulder spying is a practice where a person collects our personal data by spying over our shoulders in Cyber Cafe or ATM. Let’s learn how to hide the password for that we need to mask the password in Excel Input Box.

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.



 

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

 

Step 4: Select CommandButton from Toolbox.

 

And then drag it to the UserForm1 tab.

 

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

 

Step 6: Press F4 to get the Properties Window.

Step 7: Change the name of the Text Box to “txtPassword”

 

Step 8: Now, scroll down the Properties tab of txtPassword to assign a value of asterisk(*) in PasswordChar to create a password mask.

 

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

 

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

 

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

 

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

 

Step 12: Write the following code to see the password in the Message Box.

 

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

Step 13: Enter the password which will be hidden in the Excel window

 

Step 14: Click on Submit button so that we can see the password in the message box

 

Article Tags :