Hellyworld
New Member
- Joined
- May 3, 2017
- Messages
- 6
Hello,
I need some help with a code on Excel 2010 that is not working as expected.
How it must work:
All the sheets (43 in total) except one are on visibility 2 - xlSheetVeryHidden and the code will make visible only the necessary sheets depending on the Application.UserName. With this code I tried to filter the access on sheets of different users, power user and admins.
What is not working:
It seems that the first condition is executed but not the rest of them and all the sheets are becoming visible. If i will keep only the last condition each user will see only his tab.
If you need more details please let me know.
I need some help with a code on Excel 2010 that is not working as expected.
How it must work:
All the sheets (43 in total) except one are on visibility 2 - xlSheetVeryHidden and the code will make visible only the necessary sheets depending on the Application.UserName. With this code I tried to filter the access on sheets of different users, power user and admins.
What is not working:
It seems that the first condition is executed but not the rest of them and all the sheets are becoming visible. If i will keep only the last condition each user will see only his tab.
Code:
Private Sub Workbook_Open()
For Each ws In ActiveWorkbook.Worksheets
If Application.UserName = "admin" Then
ws.Visible = xlSheetVisible
ElseIf Application.UserName = "power user" Then
ws.Visible = xlSheetVisible
ElseIf InStr(ws.Name, Application.UserName) > 0 Then
ws.Visible = xlSheetVisible
End If
Next ws
End Sub
If you need more details please let me know.