Helloo,
I have found some code online to prompt for a password when selecting a single tab. However when I edit it to do this on several tabs it prompts for the password several times over... can anyone help please. I just want to select a sheet and it prompt for a password, instead it seems to be running the code over and over a few times. When I add more sheets to the code it increases the amount of times it wants the password..
#Confused .
Sorry I'm not that great at VBA.
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim MySheets As String, Response As String
MySheet = "Sheet3"
If ActiveSheet.Name = MySheet Then
ActiveSheet.Visible = False
Response = InputBox("Enter password to view sheet")
If Response = "MyPass3" Then
Sheets(MySheet).Visible = True
Application.EnableEvents = False
Sheets(MySheet).Select
Application.EnableEvents = True
End If
End If
Sheets(MySheet).Visible = True
Dim MySheets1 As String, Response1 As String
MySheet1 = "Sheet2"
If ActiveSheet.Name = MySheet1 Then
ActiveSheet.Visible = False
Response1 = InputBox("Enter password to view sheet")
If Response1 = "MyPass2" Then
Sheets(MySheet1).Visible = True
Application.EnableEvents = False
Sheets(MySheet1).Select
Application.EnableEvents = True
End If
End If
Sheets(MySheet1).Visible = True
End Sub
I have found some code online to prompt for a password when selecting a single tab. However when I edit it to do this on several tabs it prompts for the password several times over... can anyone help please. I just want to select a sheet and it prompt for a password, instead it seems to be running the code over and over a few times. When I add more sheets to the code it increases the amount of times it wants the password..
#Confused .
Sorry I'm not that great at VBA.
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim MySheets As String, Response As String
MySheet = "Sheet3"
If ActiveSheet.Name = MySheet Then
ActiveSheet.Visible = False
Response = InputBox("Enter password to view sheet")
If Response = "MyPass3" Then
Sheets(MySheet).Visible = True
Application.EnableEvents = False
Sheets(MySheet).Select
Application.EnableEvents = True
End If
End If
Sheets(MySheet).Visible = True
Dim MySheets1 As String, Response1 As String
MySheet1 = "Sheet2"
If ActiveSheet.Name = MySheet1 Then
ActiveSheet.Visible = False
Response1 = InputBox("Enter password to view sheet")
If Response1 = "MyPass2" Then
Sheets(MySheet1).Visible = True
Application.EnableEvents = False
Sheets(MySheet1).Select
Application.EnableEvents = True
End If
End If
Sheets(MySheet1).Visible = True
End Sub