OK
Always make a copy of the original workbook before starting, and test out the method on the copy fully to ensure you're happy with the results, before committing to the original.
Be sure to remove any of the code we mentioned earlier, if you tried it.
Go into the VBA project manager (from your w'book you can use Alt+F11).
Find your project in the L/H pane.
Double click the "This Workbook" module.
With the drop-down boxes on the RHS, select "Workbook" from the LH one, and "Open" from the RH one.
You should see this:
Code:
Private Sub Workbook_Open()
End Sub
This is where any code goes, which you want to automatically run when a user opens the workbook.
Copy the following, and paste in between the two lines you saw above:
Code:
Dim sht As Worksheet
Dim txt As String
For Each sht In ThisWorkbook.Sheets
If sht.Name <> "Sheet1" Then
sht.Visible = xlSheetVeryHidden
End If
Next
txt = InputBox("Your password please", "PASSWORD REQUIRED")
Select Case txt
Case "pword2"
With Sheets("Sheet2")
.Visible = True
.Activate
End With
Case "pword3"
With Sheets("Sheet3")
.Visible = True
.Activate
End With
Case "pword4"
With Sheets("Sheet4")
.Visible = True
.Activate
End With
Case Else
Me.Close (False): Exit Sub
End Select
The whole lot should look thus:
Code:
Private Sub Workbook_Open()
Dim sht As Worksheet
Dim txt As String
For Each sht In ThisWorkbook.Sheets
If sht.Name <> "Sheet1" Then
sht.Visible = xlSheetVeryHidden
End If
Next
txt = InputBox("Your password please", "PASSWORD REQUIRED")
Select Case txt
Case "pword2"
With Sheets("Sheet2")
.Visible = True
.Activate
End With
Case "pword3"
With Sheets("Sheet3")
.Visible = True
.Activate
End With
Case "pword4"
With Sheets("Sheet4")
.Visible = True
.Activate
End With
Case Else
Me.Close (False): Exit Sub
End Select
End Sub
In the lines ............Case "pword2" (for example), change the "pword2" to that of your manager's password who's to use sheet2 - be sure to keep the double quotation marks.
Do the same for the other Case...passwords i.e. for sheets 3 and 4.
NB don't forget to password protect your actual VBA project, otherwise users can get into there, and view the passwords for each sheet.
To protect the project, in the VBA explorer, right-click the project name, select "Project properties", select the "Protection" tab, and lock the project, along with entering a password.
Save the workbook.
Close it, then re-open it.