Use a userform.
Use a Textbox to enter the password
Use the keypress event to store the character and replace it with an asterix.
Your Macro becomes:-
Public pw As String
Sub show_ribbon()
' Select the range of cells on the active worksheet.
pw = ""
UserForm1.Show
If pw <> "PASSWORD" Then
MsgBox "Invalid password"
Exit Sub
Else
Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"", true)"
End If
End Sub
The Userform Code is:-
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
pw = pw & Chr(KeyCode)
KeyCode = 0
TextBox1.Value = TextBox1.Value & "*"
End Sub
This userform code is probably better, it is case sensitive wheras the previous one assumed capitals.:-
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
pw = pw & Chr(KeyAscii)
KeyCode = 0
TextBox1.Value = TextBox1.Value & "*"
End Sub
Bookmarks