salut à tous!!!
je code actuellement en visual basic sur excel et j'aimerai mettre sur la page d'accueil (page excel) un mot de passe. qui me permet d'avoir deux niveaux un user et un administrateur. mon mon code ne marche pas. j'aimerai avoir de l'aide s'il vous plait. voilà le code ci dessous:
je prcise aussi que sur une autre page j'ai mes users et password
Users PassWord
sylvain 1429
administrateur 4432
Option Explicit
Const T As String = "GeSC 1.0"
Private Sub Cmd_Ok_Btn_Click()
Dim Rech As Range
Dim MonParametre As Byte
Static TentativePW As Byte, TentativeID As Byte
If Txb_ID_Util = Empty Then End
Set Rech = Range("Users").Find(Txb_ID_Util, LookIn:=xlValue, lookat:=xlWhole)
If Not Rech Is Nothing Then
If Txb_Pwd_Util = Rech.Offset(0, 1) Then
MonParametre = Rech.Offset(0, 2)
MaMacro MonParametre 'ici passage de paramètres "Niveau"
Else
TentativePW = TentativePW + 1
If TentativePW > 3 Then ThisWorkbook.Close 0
MsgBox "Mot de passe invalide, Tentative N° " & TentativePW & " Sur 3", vbCritical, T
With Me.Txb_Pwd_Util
.Value = ""
.SetFocus
End With
End If
Else
TentativeID = TentativeID + 1
If TentativeID > 3 Then ThisWorkbook.Close 0
MsgBox "Utilisateur inconnu, , Tentative N° " & TentativeID & " Sur 3", vbCritical, T
With Me.Txb_ID_Util
.SetFocus
.SelStart = 0
.SelLength = Len(Me.Txb_ID_Util.Text)
End With
End If
End Sub
Private Sub UserForm_Activate()
Me.Txb_ID_Util.SetFocus
End Sub
'Convention des noms !!!
'Cmd = CommandButton
'Txb = TextBox
Private Sub UserForm_Initialize()
Dim WS As Worksheet
With Me
.Caption = T
.Txb_Pwd_Util.PasswordChar = "*"
End With
For Each WS In Worksheets
If WS.Name <> "interface" Then
WS.Visible = xlSheetVeryHidden
End If
Next
End Sub
Private Sub MaMacro(Niveau As Byte)
Select Case Niveau
Case 1
With Niv1
.Visible = True
.Activate
End With
MaSecondeMacro Me.Txb_ID_Util
Unload Me
Case 2
Call administrateur 'Appel de la macro Admin en Module1
End Select
End Sub
Private Sub MaSecondeMacro(User As String)
Dim Message As Byte
Dim Rech As Range
Set Rech = Range("Users").Find(Txb_ID_Util, LookIn:=xlValues, lookat:=xlWhole)
If (Now - Rech.Offset(0, 3)) > 30 Then
Message = MsgBox("Il apparait que votre password arrive à expiration" & vbCrLf & _
"Voulez vous changer ? ", vbQuestion + vbYesNo, T)
If Message = vbYes Then
With UserForm2
.LblUser = User 'J'utilise des Labels pour passer des arguments
.LblCell.Caption = Rech.Offset(0, 1).Address 'Idem mais sur label caché
.Show
End With
End If
End If
End Sub
Private Sub Cmd_Exit_Click()
Unload Me
End Sub
MODULE
Sub administrateur ()
Dim WS As Worksheet
For Each WS In Worksheets
If WS.Name <> "interface" Then
WS.Visible = True
End If
Next
Unload UserForm1
Niv2.Activate
End Sub
Merci
je code actuellement en visual basic sur excel et j'aimerai mettre sur la page d'accueil (page excel) un mot de passe. qui me permet d'avoir deux niveaux un user et un administrateur. mon mon code ne marche pas. j'aimerai avoir de l'aide s'il vous plait. voilà le code ci dessous:
je prcise aussi que sur une autre page j'ai mes users et password
Users PassWord
sylvain 1429
administrateur 4432
Option Explicit
Const T As String = "GeSC 1.0"
Private Sub Cmd_Ok_Btn_Click()
Dim Rech As Range
Dim MonParametre As Byte
Static TentativePW As Byte, TentativeID As Byte
If Txb_ID_Util = Empty Then End
Set Rech = Range("Users").Find(Txb_ID_Util, LookIn:=xlValue, lookat:=xlWhole)
If Not Rech Is Nothing Then
If Txb_Pwd_Util = Rech.Offset(0, 1) Then
MonParametre = Rech.Offset(0, 2)
MaMacro MonParametre 'ici passage de paramètres "Niveau"
Else
TentativePW = TentativePW + 1
If TentativePW > 3 Then ThisWorkbook.Close 0
MsgBox "Mot de passe invalide, Tentative N° " & TentativePW & " Sur 3", vbCritical, T
With Me.Txb_Pwd_Util
.Value = ""
.SetFocus
End With
End If
Else
TentativeID = TentativeID + 1
If TentativeID > 3 Then ThisWorkbook.Close 0
MsgBox "Utilisateur inconnu, , Tentative N° " & TentativeID & " Sur 3", vbCritical, T
With Me.Txb_ID_Util
.SetFocus
.SelStart = 0
.SelLength = Len(Me.Txb_ID_Util.Text)
End With
End If
End Sub
Private Sub UserForm_Activate()
Me.Txb_ID_Util.SetFocus
End Sub
'Convention des noms !!!
'Cmd = CommandButton
'Txb = TextBox
Private Sub UserForm_Initialize()
Dim WS As Worksheet
With Me
.Caption = T
.Txb_Pwd_Util.PasswordChar = "*"
End With
For Each WS In Worksheets
If WS.Name <> "interface" Then
WS.Visible = xlSheetVeryHidden
End If
Next
End Sub
Private Sub MaMacro(Niveau As Byte)
Select Case Niveau
Case 1
With Niv1
.Visible = True
.Activate
End With
MaSecondeMacro Me.Txb_ID_Util
Unload Me
Case 2
Call administrateur 'Appel de la macro Admin en Module1
End Select
End Sub
Private Sub MaSecondeMacro(User As String)
Dim Message As Byte
Dim Rech As Range
Set Rech = Range("Users").Find(Txb_ID_Util, LookIn:=xlValues, lookat:=xlWhole)
If (Now - Rech.Offset(0, 3)) > 30 Then
Message = MsgBox("Il apparait que votre password arrive à expiration" & vbCrLf & _
"Voulez vous changer ? ", vbQuestion + vbYesNo, T)
If Message = vbYes Then
With UserForm2
.LblUser = User 'J'utilise des Labels pour passer des arguments
.LblCell.Caption = Rech.Offset(0, 1).Address 'Idem mais sur label caché
.Show
End With
End If
End If
End Sub
Private Sub Cmd_Exit_Click()
Unload Me
End Sub
MODULE
Sub administrateur ()
Dim WS As Worksheet
For Each WS In Worksheets
If WS.Name <> "interface" Then
WS.Visible = True
End If
Next
Unload UserForm1
Niv2.Activate
End Sub
Merci