0 votes
in VBA by Beginner (24 points)

Dear VBA Lovers,

I wrote a code to prevent Excel file to open. It prompts for a password, but when I write the password it shows what I am typing. I need the "*" sign instead of character.

Here is the code:

Private Sub Workbook_Open()
Dim Password As String
Password = InputBox("Enter Password To Start Excel")
If Password = "Admin" Then
Else
MsgBox "Wrong Credential Closing Excel"
Application.Quit
End If
End Sub

Thanks & Regards,

Alok Ghosh

3 Answers

+1 vote
by Super Expert (2.4k points)
selected by
 
Best answer

A developer by the name of Daniel Klann made a custom InputBox years ago that automatically masks the passwords with asterisks. This custom InputBox does exactly what you want. Take a look at this tutorial for implementation instructions: Mask your Password with this VBA InputBox.

Here's a screenshot showing how the InputBox looks:

0 votes
by Beginner (132 points)
edited by

Open your file in Excel. Press F12. In the Save As dialog, click Tools (next to Save) then General Options.... Assign your password(s). Save the file. Delete your Workbook_Open code. See this article.

0 votes
by Beginner (19 points)
Don't use an Inputbox. Instead you'll need to create a userform with a textbox and probably 2 control buttons (ok and cancel) in it. After you put the textbox into the userform, right click on it and select properties. Then in the PasswordChar property type * so that when the user types in the textbox they will see only * but the textbox should save the actually password in it. I'm not at a computer right now so if you need more details for the macro and userform let me know and I can get to it tomorrow after I'm home.

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.

Register

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...