ateneva
4/22/2017 - 11:10 AM

Only hide worksheets if the user is authorises to view them

Only hide worksheets if the user is authorises to view them


Sub AuthUser()

Dim Cell As Range
Dim person As String
Dim authperson As String
person = Application.UserName
'----------------------------------------
'written by Angelina Teneva, 2013
'-----------------------------------------

For Each Cell In ActiveWorkbook.Worksheets("Names").Range("E1:E100")
    authperson = Cell.Value

If person = authperson Then
        
        Worksheets("data").Visible = xlSheetVisible
    Else
        Worksheets("data").Visible = xlSheetVeryHidden
        MsgBox ("Sorry, you are not authorized to view this data")
End If

Exit For
Next Cell

End Sub