vendredi 30 octobre 2015

Multiple If and Then Statements

Here is a the VBA code that I have, and the only thing that works is the first and last if and then statements. But the two on the middle don't. What I want to happen is if a Username opens the workbook, excel will only show the worksheet that is intended for that person. That workbook will basically have different worksheet for different people and it will be shared. Does anyone have an idea how to fix the code?

Private Sub Workbook_Open()
On Error Resume Next

If VBA.Environ("username") = "Joseph" Then
     Worksheets("Joseph").Visible = xlSheetVisible ' First sheet to be made visible
     Worksheets("Mark").Visible = xlSheetVeryHidden
     Worksheets("Joel").Visible = xlSheetVeryHidden
     Worksheets("Ed").Visible = xlSheetVeryHidden

Else

If VBA.Environ("username") = "Mark" Then
     Worksheets("Mark").Visible = xlSheetVisible ' First sheet to be made visible
     Worksheets("Joseph").Visible = xlSheetVeryHidden
     Worksheets("Joel").Visible = xlSheetVeryHidden
     Worksheets("Ed").Visible = xlSheetVeryHidden

Else

If VBA.Environ("username") = "Joel" Then
     Worksheets("Joel").Visible = xlSheetVisible ' First sheet to be made visible
     Worksheets("Ed").Visible = xlSheetVeryHidden
     Worksheets("Joseph").Visible = xlSheetVeryHidden
     Worksheets("Mark").Visible = xlSheetVeryHidden

Else

If VBA.Environ("username") = "Ed" Then
     Worksheets("Ed").Visible = xlSheetVisible ' First sheet to be made visible
     Worksheets("Joseph").Visible = xlSheetVeryHidden
     Worksheets("Mark").Visible = xlSheetVeryHidden
     Worksheets("Joel").Visible = xlSheetVeryHidden

End If
End If
End If
End If

End Sub

Aucun commentaire:

Enregistrer un commentaire