Excel VB Code password

Permabanned
Joined
24 Nov 2006
Posts
560
Hi all,

I've done the following code to password protect a sheet in Excel to make it non viewable unless the correct password is entered.

However, when the pop up box asks for the passworld to be entered, you can see what is being typed. What do I need to add to make it ************* instead? (appear as asterixs?) Thanks
Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim strPass As String
Dim lCount As Long

    If Sh.CodeName <> "Sheet8" Then
       'Set sLast variable to the last active sheet _
       This is then used to return the user to the _
       last sheet they were on if password is not known _
       or they Cancel.
       Set sLast = Sh
       
    Else
       'Hide Columns
       Sheet8.Columns.Hidden = True
           'Allow 3 attempts at password
            For lCount = 1 To 3
                strPass = InputBox(Prompt:="Password Please", Title:="PASSWORD REQUIRED")
                    If strPass = vbNullString Then 'Cancelled
                        sLast.Select
                        Exit Sub
                    ElseIf strPass <> "" Then 'InCorrect password
                        MsgBox "Password incorrect"
                    Else 'Correct Password
                       Exit For
                    End If
            Next lCount
        
            If lCount = 4 Then 'They use up their 3 attempts
                sLast.Select
                Exit Sub
            Else 'Allow viewing
                Sheet1.Columns.Hidden = False
            End If
    End If
End Sub
 
As far as im aware you cannot put a password mask on the inputbox. You can on a textbox however.

So use a form with a textbox instead of the input box control.
 
Back
Top Bottom