Passwortabfrage für einzelne Sheets macht Probleme
30.08.2025 13:06:05
MarcoR
Ich habe ein "Dashboard" für meine Mitarbeiter mit einer Startseite und 5 Arbeitsblättern erstellt.
Auf der Startseite befinden sich 5 Buttons mit einer jeweiligen Passwortabfrage um auf die dazugehörige Seite zugreifen zu können. Der VBA Code den ich habe, funktioniert soweit ganz gut, nur habe ich Probleme, wenn ich ein Passwort falsch eingebe.
Ich werde dann immer auf das nächste Tabellenblatt weitergeleitet, was ich eigentlich nicht will.
Meine Vorstellung war, dass wenn man ein falsches Passwort eingibt, man wieder auf die Startseite geführt wird.
Was muss ich in dem Code ändern, oder hinzufügen?
Vielen Dank im voraus und ein schönes Wochenende.
Hier mein Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim xSheetName As String
xSheetName = "Verwaltung"
If Application.ActiveSheet.Name = xSheetName Then
Application.EnableEvents = False
Application.ActiveSheet.Visible = False
xTitleId = "Zugang Verwaltung"
response = Application.InputBox("Password", xTitleId, "", Type:=2)
If response = "admin1" Then
Application.Sheets(xSheetName).Visible = True
Application.Sheets(xSheetName).Select
End If
Application.Sheets(xSheetName).Visible = True
Application.EnableEvents = True
End If
xSheetName = "Technik"
If Application.ActiveSheet.Name = xSheetName Then
Application.EnableEvents = False
Application.ActiveSheet.Visible = False
xTitleId = "Zugang Technik"
response = Application.InputBox("Password", xTitleId, "", Type:=2)
If response = "admin2" Then
Application.Sheets(xSheetName).Visible = True
Application.Sheets(xSheetName).Select
End If
Application.Sheets(xSheetName).Visible = True
Application.EnableEvents = True
End If
xSheetName = "Schlupf"
If Application.ActiveSheet.Name = xSheetName Then
Application.EnableEvents = False
Application.ActiveSheet.Visible = False
xTitleId = "Zugang Schlupf"
response = Application.InputBox("Password", xTitleId, "", Type:=2)
If response = "admin3" Then
Application.Sheets(xSheetName).Visible = True
Application.Sheets(xSheetName).Select
End If
Application.Sheets(xSheetName).Visible = True
Application.EnableEvents = True
End If
xSheetName = "Ein-Umlage"
If Application.ActiveSheet.Name = xSheetName Then
Application.EnableEvents = False
Application.ActiveSheet.Visible = False
xTitleId = "Zugang Ein-Umlage"
response = Application.InputBox("Password", xTitleId, "", Type:=2)
If response = "admin4" Then
Application.Sheets(xSheetName).Visible = True
Application.Sheets(xSheetName).Select
End If
Application.Sheets(xSheetName).Visible = True
Application.EnableEvents = True
End If
xSheetName = "QS"
If Application.ActiveSheet.Name = xSheetName Then
Application.EnableEvents = False
Application.ActiveSheet.Visible = False
xTitleId = "Zugang QS"
response = Application.InputBox("Password", xTitleId, "", Type:=2)
If response = "admin5" Then
Application.Sheets(xSheetName).Visible = True
Application.Sheets(xSheetName).Select
End If
Application.Sheets(xSheetName).Visible = True
Application.EnableEvents = True
End If
End Sub
Anzeige