Link to home
Start Free TrialLog in
Avatar of ilrosebud26
ilrosebud26Flag for United States of America

asked on

Can you hide password from being displayed as it is typed (Input box)?

I have a input box which prompts for a password (in excel) but I do not want the password displayed as it is typed.  I have searched on this is the site and see other questions which are similar but not quite the same.  Is this possible?
Avatar of mvidas
mvidas
Flag of United States of America image

Hi,

It is possible, just not with the built-in inputbox. You'd have to create a userform with a textbox on it, and set the .PasswordChar property to "*" or whatever character you want to show up in place of the actual input.

I made one a while back, I can upload it for you, might save you a couple minutes.
http://www.mvidas.com/mvfiles/vInputBox.zip

Unzip it, and import the .bas and .frm files into your project (or just copy the code from the .bas into an existing module). Then just call vInputBox instead of just InputBox, and set the vMaskInput variable to True, ie:

 Dim YourPassword As String
 YourPassword = vInputBox("Please enter password", vMaskInput:=True)

If you don't want the inputbox to be always on top (necessary for my usage), remove the UserForm_Activate subroutine.

Matt
It is possible but it would be much easier to build a simple userform with a text box and OK button, because then you can just set the PasswordChar property of the text box. If you want to do it with an InputBox, you need code like this: https://www.experts-exchange.com/questions/20949769/Password-Mask-for-MS-Access-Inputbox.html

Regards,
Rory
Avatar of ilrosebud26

ASKER

Matt-
    Thanks for the help.  I think I will go with the lesser of two evils.  For someone like me (who just statred doing vb) it seems easierjust  to build a user form with a textbox.  Others may disagree.

Rosemary
Hi Rosemary,

I'll admit, I tried what Rory posted and do find it quite interesting, though I agree that the userform is the easier way to go. I just made my own inputbox userform (the linked file above) look like the built-in one with the same arguments to pass to it but adding the vMaskInput argument :)

Matt
Matt-
     I guess you can really tell than I am new at this.  Here is my vb (very simple, I know).  Where do I put the mask?

Private Sub OKButton1_Click()
    If TextBox1 = "password" Then
            ActiveWorkbook.Unprotect TextBox1
            Unload Me
            Sheets("Sheet2").Select
        Else
            MsgBox "Invalid password, please try again."
            TextBox1 = " "
    End If
End Sub

Rosemary
ASKER CERTIFIED SOLUTION
Avatar of mvidas
mvidas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You are the best....thanks for your help!!

Rosemary
Glad to help! And remember you can always use the one I have above (or use the same idea with a public variable to store the inputted text) if you want to make it more generally usable; really only useful if you want to store the password in a variable or will use it more than once in a routine, so the userform doesnt actually do anything except take input.

Remember that we're here if you have any more questions
Matt