Anzeige
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Anzeige
Inhaltsverzeichnis

Passwortabfrage für einzelne Sheets macht Probleme

Forumthread: Passwortabfrage für einzelne Sheets macht Probleme

Passwortabfrage für einzelne Sheets macht Probleme
30.08.2025 13:06:05
MarcoR
Hallo zusammen

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

10
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Passwortabfrage für einzelne Sheets macht Probleme
30.08.2025 13:41:37
Dirk
Hallo MarcoR,

probier es mal hiermit :

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

If response > "admin1" Then GoTo weiter

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

If response > "admin2" Then GoTo weiter

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

If response > "admin3" Then GoTo weiter

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

If response > "admin4" Then GoTo weiter

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

If response > "admin5" Then GoTo weiter

Application.Sheets(xSheetName).Visible = True
Application.EnableEvents = True
End If


weiter:

Exit Sub
Anzeige
AW: Passwortabfrage für einzelne Sheets macht Probleme
30.08.2025 15:42:35
Ulf
Hi,
nehme an, du benutzt deine Schaltflächen um Worksheet.Activate aufzurufen.
Hier eine Minimalversion ohne größere Fehlerbehandlung
https://www.herber.de/bbs/user/178783.xlsm
hth
Ulf
AW: Passwortabfrage für einzelne Sheets macht Probleme
30.08.2025 17:55:47
daniel
Hi

Die Passwortabfrage sollte in den Code des Buttons, mit dem du das Blatt aktivierst, also nach dem Schema

PW = Inputbox("Passwort Blatt xx")

if PW = "korrektes Passwort" then
With Sheets("xx")
.visible = xlsheetvisible
.Select
End with
Else
msgbox "Passwort falsch"
End if

Wenn du die Anfrage im Activate-Event machst, ist es ja eigentlich schon zu spät.

Gruß Daniel

Anzeige
AW: Passwortabfrage für einzelne Sheets macht Probleme
30.08.2025 16:16:42
MarcoR
Vielen Dank für die Hilfe, ich versuche mal die Codes einzubauen.

Ich habe auch die Datei mal hochgeladen, um visuell ein Bild zu haben
AW: Passwortabfrage für einzelne Sheets macht Probleme
30.08.2025 17:51:32
MarcoR
Oh WOW.
Jetzt bin ich Baff....
Genau meine Vorstellungen. Vielen lieben Dank. ich werd mal den Code genauer unter die Lupe nehmen um mehr zu lernen.
Tausend Dank nochmal.

schönes Wochenende.
Anzeige
AW: Passwortabfrage für einzelne Sheets macht Probleme
30.08.2025 14:13:44
MarcoR
Hallo Dirk
Vielen Dank für Deine Antwort.
So an sich funktioniert das schon, aber bei falscher Eingabe wird das Tabellenblatt (z.B. Verwaltung) ausgeblendet und kann dann nicht mehr darauf zugreifen.
Bei richtiger Eingabe, soll er in das Tabellenblatt wechseln....macht er...bei falscher Eingabe springt er einfach auf das nächste Tabellenblatt für die PW Eingabe. Und genau das möchte ich vermeiden. Bei falscher Eingabe soll er entweder dort bleiben und eine Info zeigen, dass die Eingabe falsch war und man kann es nochmal probieren, oder eben bei falscher Eingabe nichts macht und bei der Startseite bleibt.
Die Blätter sind so benannt wie beschrieben:
Startseite (von da aus will ich zugreifen - hab 5 Buttons mit Verlinkung zum jeweiligen Blatt)
Verwaltung
Technik
Schlupf
Ein-Umlage
QS
Anzeige
AW: Passwortabfrage für einzelne Sheets macht Probleme
30.08.2025 15:09:21
Dirk
Hallo MarcoR,

teste das noch mal ....

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

If response > "admin1" Then
MsgBox "Falsches Passwort !", , "Ergebnis"
Application.ActiveSheet.Visible = True
Application.EnableEvents = True
Sheets("Startseite").Select
Exit Sub
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

If response > "admin2" Then
MsgBox "Falsches Passwort !", , "Ergebnis"
Application.ActiveSheet.Visible = True
Application.EnableEvents = True
Sheets("Startseite").Select
Exit Sub
End If

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

If response > "admin3" Then
MsgBox "Falsches Passwort !", , "Ergebnis"
Application.ActiveSheet.Visible = True
Application.EnableEvents = True
Sheets("Startseite").Select
Exit Sub
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

If response > "admin4" Then
MsgBox "Falsches Passwort !", , "Ergebnis"
Application.ActiveSheet.Visible = True
Application.EnableEvents = True
Sheets("Startseite").Select
Exit Sub
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

If response > "admin5" Then
MsgBox "Falsches Passwort !", , "Ergebnis"
Application.ActiveSheet.Visible = True
Application.EnableEvents = True
Sheets("Startseite").Select
Exit Sub
End If

Application.Sheets(xSheetName).Visible = True
Application.EnableEvents = True
End If

End Sub
Anzeige
AW: Passwortabfrage für einzelne Sheets macht Probleme
30.08.2025 16:06:11
MarcoR
Vielen Dank für eure Hilfe, aber ich komm irgendwie nicht weiter.
Wenn das Passwort korrekt ist, funktioniert es, wenn es falsch ist, blendet es das Arbeitsblatt aus und ich kann es nicht mehr über den Button ansteuern.

Ich habe mal das "grobe" Dashboard hochgeladen, mit Dirk seinem Code, so soll es auch in etwa funktionieren, nur leider ist das Schade, das bei falscheingabe dann nichts mehr geht.

https://www.herber.de/bbs/user/178784.xlsm
Anzeige

Forumthreads zu verwandten Themen

Anzeige
Anzeige
Anzeige