Masking password characters in VBA code

BenKenya

New Member
Joined
Jul 23, 2020
Messages
9
Office Version
  1. 365
Platform
  1. MacOS
Dear Mr Excel,

I have created a password activated spreadsheet, but I cannot find how to 'Mask' the characters of the password box, does anyone know how to help?

I have created the code below;

Sub Run_Password_Admin_Macro()

'Password protect for Admin

Dim strPassTry As String
Dim strPassword As String
Dim lTries As Long
Dim bSuccess As Boolean
strPassword = "Password123"
For lTries = 1 To 3
strPassTry = InputBox("Enter Password please", "RUN MACRO")
If strPassTry = vbNullString Then Exit Sub
bSuccess = strPassword = strPassTry
If bSuccess = True Then Exit For
MsgBox "Password incorrect"
Next lTries

If bSuccess = True Then Run "Unhide_Admin_sheets"

MsgBox "Welcome"

This works great, but i would like the characters to show ****** in the input box. I have found some information on line but I am not sure how to input into my code, the code below refers;

Dim strPasswd As String
Dim strAsterisks As String

Sub tbxPassword_Change()

strAsterisks = strAsterisks & "*"

strPassword = strPassword & Right(tbxPassword.Txt, 1)
tbxPassword.Txt = Asterisks
End Sub

Sub CommandButton_click()
PasswordChecker strPasswd
Unload Me
End Sub

Is it possible?

Thank you

Ben
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
It would be easier to use a UserForm with a Textbox and in the properties of the TextBox you can assign the Mask character you want.
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top