Option Explicit
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
UserName = UserVerification.UserName.Text
Password = UserVerification.Password.Text
With Sheets("UserNames").Range("A:A")
Set c = .Find(What:=UserName, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True)
End With
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 = Sheets("UserNames").Range(c.Address).Offset(0, 1).Text Then
ThisWorkbook.Unprotect Password:="Password"
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 MyError <> 0 Then
MsgBox "The sheet specified could not be shown, please contact your system " & _
"administrator.", vbCritical, "Sheet Specification Error"
Exit Sub
End If
Else
MsgBox "The password you have specified is incorrect, please try again.", vbCritical, _
"Incorrect Password"
Exit Sub
End If
Unload Me
End Sub
Option Explicit
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Cancel = True
If ActiveSheet.Name <> "UserNames" Then
ThisWorkbook.Unprotect Password:="Password"
ActiveSheet.Visible = xlVeryHidden
ThisWorkbook.Protect Password:="Password", Structure:=True
End If
End Sub
|