Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet
Sheets("Public").Visible = True
For Each ws In Worksheets
If ws.Name <> "Public" Then ws.Visible = xlSheetVeryHidden
Next ws
ThisWorkbook.Save
End Sub
Private Sub Workbook_Open()
Dim user As String, pwd As String, Correctpwd As String, Status As String
Dim ct As Long, LR As Long, i As Long
Dim C As Range
Dim ws As Worksheet
Dim AllowedSheets
LR = Sheets("LogIn").Cells(Rows.Count, "A").End(xlUp).Row
user = InputBox("Enter your UserName")
Set C = Worksheets("LogIn").Range("$A1:$A" & LR).Find(What:=user, LookIn:=xlValues, MatchCase:=False, SearchFormat:=False)
If Not C Is Nothing Then
Status = C.Offset(, 2)
Correctpwd = C.Offset(, 3)
Do While ct < 3 And pwd <> Correctpwd
pwd = InputBox("Enter Password: " & 3 - ct & " tries left")
ct = ct + 1
Loop
If pwd = Correctpwd Then
Application.ScreenUpdating = False
If Status = "User" Then
AllowedSheets = Split(C.Offset(, 1).Value, "/")
For i = 0 To UBound(AllowedSheets)
Sheets(AllowedSheets(i)).Visible = True
Next i
Else
For Each ws In Worksheets
ws.Visible = True
Next ws
End If
If Status <> "Admin" Then
Sheets("LogIn").Visible = xlVeryHidden
End If
Application.ScreenUpdating = True
End If
Else
MsgBox "Not a valid user, access to other sheets denied"
End If
End Sub