Hide Macro Password Characters

  • Thread starter Thread starter Morgimo
  • Start date Start date
M

Morgimo

I have the following code:

If InputBox("To run update, please enter the password:") <> "password" Then
Exit Sub

What is the code to get the password to display as ******** as they type?

Thanks,
Jacob
 
Hi Jacob

It can only be done in an userform.

Create an userform with a Textbox and two buttons ( OK/Cancel). Select
the Textbox and open the Properties window (F4) and find the
PasswordChar property and enter * in the filed next to it.

Hopes this helps.
....
Per
 
Jacob,

A few years ago I found a solution for this dilemma on one of the many
Excel message boards So here it goes:

The inputbox is a native component and can't be modified insomuch as
you describe. However if you make your own form you can use a textbox
instead and set the textbox to have an inputmask. For the new form in
VB6 or newer you can set the passwordchar property to *

First in your code you have to replace:

YourPassword = InputBox("Please enter your password")

with

YourPassword = frmPass.Raise

Then in the new password form code:
--------------------------------------------------------------

Option Explicit
Dim strPassword As String

Private Sub cmdOkay_Click()
strPassword = txtPass.Value
Me.Hide
End Sub

Public Function Raise() As String
Me.Show vbModal
Raise = strPassword
End Function
 
Back
Top