'################################
'VALIDATION DES MOTS DE PASSE
'################################
Private Sub CommandButton1_Click()
Dim i
Dim ligne As Long
'Ne pas beugguer sur une erreur
On Error Resume Next
Select Case Me.TextBox1.Value
Case "123", "Wil", "Roul"
ligne = Sheets("main_courante").Range("A65536").End(xlUp).Row + 1
Sheets("main_courante").Cells(ligne, 1) = Environ("USERNAME")
Sheets("main_courante").Cells(ligne, 2) = TextBox1.Value
Sheets("main_courante").Cells(ligne, 3) = Date
TextBox1 = ""
'Décharger l'userform
'Ouvrir la page d'accueil
Sheets("bd1").Visible = True
Sheets("bd3").Visible = True
[COLOR="Magenta"]protection "bd1", True
protection "bd3", True[/COLOR]
Unload Me
Case "321", "Cav", "Car" 'saisie du mot de passe2
ligne = Sheets("main_courante").Range("A65536").End(xlUp).Row + 1
Sheets("main_courante").Cells(ligne, 1) = Environ("USERNAME")
Sheets("main_courante").Cells(ligne, 2) = TextBox1.Value
Sheets("main_courante").Cells(ligne, 3) = Date
TextBox1 = ""
'Décharger l'userform
Unload Me
'Ouvrir la page d'accueil
Sheets("bd3").Visible = True
Sheets("bd4").Visible = True
Sheets("bd5").Visible = True
[COLOR="Magenta"] protection "bd3", True
protection "bd4", True
protection "bd5", True[/COLOR]
Case "admin"
Me.CommandButton2.Visible = True
Case ""
Sheets("bd1").Visible = True
Sheets("bd3").Visible = True
Sheets("bd2").Visible = True
[COLOR="Magenta"] protection "bd1", False
protection "bd3", False
protection "bd2", False[/COLOR]
Unload Me
Case Else 'Message d'erreur si mot de passe incorrect
MsgBox "Mot de passe invalide", vbOKOnly, "Password"
'Vider la textbox
TextBox1 = ""
Exit Sub
End Select
End Sub
Private Sub CommandButton2_Click()
Sheets("accueil").Activate
Dim i
For i = 1 To Sheets.Count
If Sheets(i).Name <> "ACCUEIL" Then
Sheets(i).Visible = True
[COLOR="Magenta"]protection Sheets(i).Name, True[/COLOR]
End If
Next
MsgBox "ONGLETS DEVERROUILLES", vbOKOnly, "Password"
Unload PASSE
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub UserForm_INITIALIZE()
Me.CommandButton2.Visible = False
End Sub
'
[COLOR="Red"]Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)[/COLOR]
If CloseMode = vbFormControlMenu Then Cancel = True
End Sub
[COLOR="Red"]Private Sub protection(nomfeuille As String, liberer As Boolean)[/COLOR]
Dim motdepasse As String
motdepasse = "azc548fkyUbC"
If liberer = True Then
Sheets(nomfeuille).Unprotect motdepasse
Else
Sheets(nomfeuille).Protect Password:=motdepasse, DrawingObjects:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True, AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
End If
End Sub