Auto Log In


New Member
Oct 13, 2015
Hi All

I have Log In Security within a Workbook which is activated by Clicking a button [CommandButton2]. However, what I need is, if a User clicks the other button [CommandButton1] then it will open the workbook and all sheets [except Admin & Lists] so they can view the content.

I cannot work this out at all

Anyhelp gratefully received




Well-known Member
Aug 31, 2016
Private Sub Cancel_Click()

    Unload Me

End Sub

Private Sub OK_Click()

Dim c               As Object
Dim UserName        As String
Dim Password        As String
Dim MyError         As Integer
    'Assign UserName to a variable
    UserName = UserVerification.UserName.Text
    'Assign Password to a variable
    Password = UserVerification.Password.Text
    'Specify the sheet and range to look up the UserName
    With Sheets("UserNames").Range("A:A")
        Set c = .Find(What:=UserName, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True)
    End With
    'If UserName cannot be found
    If c Is Nothing Then
        MsgBox "The username you have inputted is invalid, please try again.", vbCritical, "Incorrect UserName"
        Exit Sub
    End If
    'If Password is correct
    If Password = Sheets("UserNames").Range(c.Address).Offset(0, 1).Text Then
        ThisWorkbook.Unprotect Password:="Password"
        'If the sheet to make visible is not in the workbook an error will occur
        'If there is no error then make that sheet visible
        On Error Resume Next
        Sheets(Range(c.Address).Offset(0, 2).Text).Visible = True
        MyError = Err
        On Error GoTo 0
        ThisWorkbook.Protect Password:="Password", Structure:=True
        'If there was an error let the user know to try again.
        If MyError <> 0 Then
            MsgBox "The sheet specified could not be shown, please contact your system administrator.", vbCritical, "Sheet Specification Error"
            Exit Sub
        End If
        'If the password is incorrect let the user know to try again
        MsgBox "The password you have specified is incorrect, please try again.", vbCritical, "Incorrect Password"
        Exit Sub
    End If
    'Dismiss the userform
    Unload Me

End Sub
Download workbook :

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...