OVH Cloud OVH Cloud

A l'aide .......... Combobox

7 réponses
Avatar
YANN24
Bonjour,
j'ai un gros Pb. Avant, cette combobox fonctionnait très bien (sauf
l'administrateur, mais c'était pas si grave). Mais j'y ai rajouté "2004", et
ça plante. Il me met "erreur de compilation dans le module caché :
Userform1". POURQUOI ??
Je vous remercie, car je suis vraiment dans le "caca". Merci de votre aide.
YANN

Private Declare Function GetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub CommandButton2_Click()
'si l'utilisateur clique sur Annuler, on quitte.
Unload Me
ThisWorkbook.Close
End Sub

Private Sub UserForm_Initialize()
'empêche l'affichage de la croix de fermeture en utilisant les API
'déclarées en début de module
Dim hwnd As Long
hwnd = FindWindowA("Thunder" & IIf(Application.Version Like "8*", "X", "D")
& "Frame", Me.Caption)
SetWindowLongA hwnd, -16, GetWindowLongA(hwnd, -16) And &HFFF7FFFF

With Me.ComboBox1
.AddItem "2004"
.AddItem "2005"
.AddItem "2006"
.AddItem "Administrateur"
End With

Me.TextBox1.Visible = False
Me.Label1.Visible = False
End Sub

Private Sub combobox1_Click()
Select Case Me.ComboBox1.Value

Case "2004"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 11 To 16
Sheets(I).Visible = True
Next
For I = 17 To 42
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "2005"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 17 To 29
Sheets(I).Visible = True
Next
For I = 11 To 16
Sheets(I).Visible = xlSheetVeryHidden
Next
For I = 30 To 42
Sheets(I).Visible = xlSheetVeryHidden
ActiveWorkbook.Protect
Unload Me

Case "2006"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 30 To 42
Sheets(I).Visible = True
Next
For I = 11 To 29
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "Administateur"

With Me
.ComboBox1.Visible = False
With .TextBox1
.Visible = True
.SetFocus
End With
.Label1.Visible = True
End With

End Select
End Sub
Private Sub commandbutton1_Click()

If Me.ComboBox1.Value = "" Then
MsgBox "vous n'avez rien saisi"
Me.ComboBox1.SetFocus
Else
If TextBox1.Value = "" Then
Else
If controlmdp(TextBox1.Value) = True Then
ThisWorkbook.IsAddin = False
For I = 1 To ThisWorkbook.Sheets.Count
Sheets(I).Visible = True
Next
Unload Me
End If
End If
End If

End Sub
Function controlmdp(nommdp)
On Error Resume Next
tabmdp = Array("passe")
trouve = Application.WorksheetFunction.HLookup(nommdp, tabmdp, 1, False)
If Err.Number <> 0 Then
Err.Clear
MsgBox "Vous n'êtes pas autoriser à pénétrer cet espace réservé"
Else
MsgBox "Autorisation acceptée"
controlmdp = True
End If
End Function

7 réponses

Avatar
papou
Bonjour
Il faudrait peut-être pouvoir identifier la ligne de l'erreur !
Déprotège ton projet et fais tourner la macro pas à pas en mode debogage.
Cordialement
Pascal

"YANN24" a écrit dans le message de news:

Bonjour,
j'ai un gros Pb. Avant, cette combobox fonctionnait très bien (sauf
l'administrateur, mais c'était pas si grave). Mais j'y ai rajouté "2004",
et
ça plante. Il me met "erreur de compilation dans le module caché :
Userform1". POURQUOI ??
Je vous remercie, car je suis vraiment dans le "caca". Merci de votre
aide.
YANN

Private Declare Function GetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As
Long

Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub CommandButton2_Click()
'si l'utilisateur clique sur Annuler, on quitte.
Unload Me
ThisWorkbook.Close
End Sub

Private Sub UserForm_Initialize()
'empêche l'affichage de la croix de fermeture en utilisant les API
'déclarées en début de module
Dim hwnd As Long
hwnd = FindWindowA("Thunder" & IIf(Application.Version Like "8*", "X",
"D")
& "Frame", Me.Caption)
SetWindowLongA hwnd, -16, GetWindowLongA(hwnd, -16) And &HFFF7FFFF

With Me.ComboBox1
.AddItem "2004"
.AddItem "2005"
.AddItem "2006"
.AddItem "Administrateur"
End With

Me.TextBox1.Visible = False
Me.Label1.Visible = False
End Sub

Private Sub combobox1_Click()
Select Case Me.ComboBox1.Value

Case "2004"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 11 To 16
Sheets(I).Visible = True
Next
For I = 17 To 42
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "2005"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 17 To 29
Sheets(I).Visible = True
Next
For I = 11 To 16
Sheets(I).Visible = xlSheetVeryHidden
Next
For I = 30 To 42
Sheets(I).Visible = xlSheetVeryHidden
ActiveWorkbook.Protect
Unload Me

Case "2006"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 30 To 42
Sheets(I).Visible = True
Next
For I = 11 To 29
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "Administateur"

With Me
.ComboBox1.Visible = False
With .TextBox1
.Visible = True
.SetFocus
End With
.Label1.Visible = True
End With

End Select
End Sub
Private Sub commandbutton1_Click()

If Me.ComboBox1.Value = "" Then
MsgBox "vous n'avez rien saisi"
Me.ComboBox1.SetFocus
Else
If TextBox1.Value = "" Then
Else
If controlmdp(TextBox1.Value) = True Then
ThisWorkbook.IsAddin = False
For I = 1 To ThisWorkbook.Sheets.Count
Sheets(I).Visible = True
Next
Unload Me
End If
End If
End If

End Sub
Function controlmdp(nommdp)
On Error Resume Next
tabmdp = Array("passe")
trouve = Application.WorksheetFunction.HLookup(nommdp, tabmdp, 1, False)
If Err.Number <> 0 Then
Err.Clear
MsgBox "Vous n'êtes pas autoriser à pénétrer cet espace réservé"
Else
MsgBox "Autorisation acceptée"
controlmdp = True
End If
End Function



Avatar
YANN24
re,
alors, en fait, il bloc sur le Case "2006", en surlignant Case.
Si tu peux m'aider.
Merci. YANN


Bonjour
Il faudrait peut-être pouvoir identifier la ligne de l'erreur !
Déprotège ton projet et fais tourner la macro pas à pas en mode debogage.
Cordialement
Pascal

"YANN24" a écrit dans le message de news:

Bonjour,
j'ai un gros Pb. Avant, cette combobox fonctionnait très bien (sauf
l'administrateur, mais c'était pas si grave). Mais j'y ai rajouté "2004",
et
ça plante. Il me met "erreur de compilation dans le module caché :
Userform1". POURQUOI ??
Je vous remercie, car je suis vraiment dans le "caca". Merci de votre
aide.
YANN

Private Declare Function GetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As
Long

Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub CommandButton2_Click()
'si l'utilisateur clique sur Annuler, on quitte.
Unload Me
ThisWorkbook.Close
End Sub

Private Sub UserForm_Initialize()
'empêche l'affichage de la croix de fermeture en utilisant les API
'déclarées en début de module
Dim hwnd As Long
hwnd = FindWindowA("Thunder" & IIf(Application.Version Like "8*", "X",
"D")
& "Frame", Me.Caption)
SetWindowLongA hwnd, -16, GetWindowLongA(hwnd, -16) And &HFFF7FFFF

With Me.ComboBox1
.AddItem "2004"
.AddItem "2005"
.AddItem "2006"
.AddItem "Administrateur"
End With

Me.TextBox1.Visible = False
Me.Label1.Visible = False
End Sub

Private Sub combobox1_Click()
Select Case Me.ComboBox1.Value

Case "2004"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 11 To 16
Sheets(I).Visible = True
Next
For I = 17 To 42
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "2005"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 17 To 29
Sheets(I).Visible = True
Next
For I = 11 To 16
Sheets(I).Visible = xlSheetVeryHidden
Next
For I = 30 To 42
Sheets(I).Visible = xlSheetVeryHidden
ActiveWorkbook.Protect
Unload Me

Case "2006"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 30 To 42
Sheets(I).Visible = True
Next
For I = 11 To 29
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "Administateur"

With Me
.ComboBox1.Visible = False
With .TextBox1
.Visible = True
.SetFocus
End With
.Label1.Visible = True
End With

End Select
End Sub
Private Sub commandbutton1_Click()

If Me.ComboBox1.Value = "" Then
MsgBox "vous n'avez rien saisi"
Me.ComboBox1.SetFocus
Else
If TextBox1.Value = "" Then
Else
If controlmdp(TextBox1.Value) = True Then
ThisWorkbook.IsAddin = False
For I = 1 To ThisWorkbook.Sheets.Count
Sheets(I).Visible = True
Next
Unload Me
End If
End If
End If

End Sub
Function controlmdp(nommdp)
On Error Resume Next
tabmdp = Array("passe")
trouve = Application.WorksheetFunction.HLookup(nommdp, tabmdp, 1, False)
If Err.Number <> 0 Then
Err.Clear
MsgBox "Vous n'êtes pas autoriser à pénétrer cet espace réservé"
Else
MsgBox "Autorisation acceptée"
controlmdp = True
End If
End Function








Avatar
YANN24
Re,
non, dsl
Il bloque sur le Private Sub (tout est surligné en jaune.)
MErci de ton aide.
YANN


Bonjour
Il faudrait peut-être pouvoir identifier la ligne de l'erreur !
Déprotège ton projet et fais tourner la macro pas à pas en mode debogage.
Cordialement
Pascal

"YANN24" a écrit dans le message de news:

Bonjour,
j'ai un gros Pb. Avant, cette combobox fonctionnait très bien (sauf
l'administrateur, mais c'était pas si grave). Mais j'y ai rajouté "2004",
et
ça plante. Il me met "erreur de compilation dans le module caché :
Userform1". POURQUOI ??
Je vous remercie, car je suis vraiment dans le "caca". Merci de votre
aide.
YANN

Private Declare Function GetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As
Long

Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub CommandButton2_Click()
'si l'utilisateur clique sur Annuler, on quitte.
Unload Me
ThisWorkbook.Close
End Sub

Private Sub UserForm_Initialize()
'empêche l'affichage de la croix de fermeture en utilisant les API
'déclarées en début de module
Dim hwnd As Long
hwnd = FindWindowA("Thunder" & IIf(Application.Version Like "8*", "X",
"D")
& "Frame", Me.Caption)
SetWindowLongA hwnd, -16, GetWindowLongA(hwnd, -16) And &HFFF7FFFF

With Me.ComboBox1
.AddItem "2004"
.AddItem "2005"
.AddItem "2006"
.AddItem "Administrateur"
End With

Me.TextBox1.Visible = False
Me.Label1.Visible = False
End Sub

Private Sub combobox1_Click()
Select Case Me.ComboBox1.Value

Case "2004"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 11 To 16
Sheets(I).Visible = True
Next
For I = 17 To 42
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "2005"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 17 To 29
Sheets(I).Visible = True
Next
For I = 11 To 16
Sheets(I).Visible = xlSheetVeryHidden
Next
For I = 30 To 42
Sheets(I).Visible = xlSheetVeryHidden
ActiveWorkbook.Protect
Unload Me

Case "2006"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 30 To 42
Sheets(I).Visible = True
Next
For I = 11 To 29
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "Administateur"

With Me
.ComboBox1.Visible = False
With .TextBox1
.Visible = True
.SetFocus
End With
.Label1.Visible = True
End With

End Select
End Sub
Private Sub commandbutton1_Click()

If Me.ComboBox1.Value = "" Then
MsgBox "vous n'avez rien saisi"
Me.ComboBox1.SetFocus
Else
If TextBox1.Value = "" Then
Else
If controlmdp(TextBox1.Value) = True Then
ThisWorkbook.IsAddin = False
For I = 1 To ThisWorkbook.Sheets.Count
Sheets(I).Visible = True
Next
Unload Me
End If
End If
End If

End Sub
Function controlmdp(nommdp)
On Error Resume Next
tabmdp = Array("passe")
trouve = Application.WorksheetFunction.HLookup(nommdp, tabmdp, 1, False)
If Err.Number <> 0 Then
Err.Clear
MsgBox "Vous n'êtes pas autoriser à pénétrer cet espace réservé"
Else
MsgBox "Autorisation acceptée"
controlmdp = True
End If
End Function








Avatar
YANN24
Re,
le message d'erreur est "Case sans select Case"
Merci. YANN


Bonjour
Il faudrait peut-être pouvoir identifier la ligne de l'erreur !
Déprotège ton projet et fais tourner la macro pas à pas en mode debogage.
Cordialement
Pascal

"YANN24" a écrit dans le message de news:

Bonjour,
j'ai un gros Pb. Avant, cette combobox fonctionnait très bien (sauf
l'administrateur, mais c'était pas si grave). Mais j'y ai rajouté "2004",
et
ça plante. Il me met "erreur de compilation dans le module caché :
Userform1". POURQUOI ??
Je vous remercie, car je suis vraiment dans le "caca". Merci de votre
aide.
YANN

Private Declare Function GetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As
Long

Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub CommandButton2_Click()
'si l'utilisateur clique sur Annuler, on quitte.
Unload Me
ThisWorkbook.Close
End Sub

Private Sub UserForm_Initialize()
'empêche l'affichage de la croix de fermeture en utilisant les API
'déclarées en début de module
Dim hwnd As Long
hwnd = FindWindowA("Thunder" & IIf(Application.Version Like "8*", "X",
"D")
& "Frame", Me.Caption)
SetWindowLongA hwnd, -16, GetWindowLongA(hwnd, -16) And &HFFF7FFFF

With Me.ComboBox1
.AddItem "2004"
.AddItem "2005"
.AddItem "2006"
.AddItem "Administrateur"
End With

Me.TextBox1.Visible = False
Me.Label1.Visible = False
End Sub

Private Sub combobox1_Click()
Select Case Me.ComboBox1.Value

Case "2004"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 11 To 16
Sheets(I).Visible = True
Next
For I = 17 To 42
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "2005"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 17 To 29
Sheets(I).Visible = True
Next
For I = 11 To 16
Sheets(I).Visible = xlSheetVeryHidden
Next
For I = 30 To 42
Sheets(I).Visible = xlSheetVeryHidden
ActiveWorkbook.Protect
Unload Me

Case "2006"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 30 To 42
Sheets(I).Visible = True
Next
For I = 11 To 29
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "Administateur"

With Me
.ComboBox1.Visible = False
With .TextBox1
.Visible = True
.SetFocus
End With
.Label1.Visible = True
End With

End Select
End Sub
Private Sub commandbutton1_Click()

If Me.ComboBox1.Value = "" Then
MsgBox "vous n'avez rien saisi"
Me.ComboBox1.SetFocus
Else
If TextBox1.Value = "" Then
Else
If controlmdp(TextBox1.Value) = True Then
ThisWorkbook.IsAddin = False
For I = 1 To ThisWorkbook.Sheets.Count
Sheets(I).Visible = True
Next
Unload Me
End If
End If
End If

End Sub
Function controlmdp(nommdp)
On Error Resume Next
tabmdp = Array("passe")
trouve = Application.WorksheetFunction.HLookup(nommdp, tabmdp, 1, False)
If Err.Number <> 0 Then
Err.Clear
MsgBox "Vous n'êtes pas autoriser à pénétrer cet espace réservé"
Else
MsgBox "Autorisation acceptée"
controlmdp = True
End If
End Function








Avatar
isabelle
bonjour Yann,

il manque un Next à:
Case "2005"
..
For I = 30 To 42
Sheets(I).Visible = xlSheetVeryHidden
'---> ici

isabelle


Re,
le message d'erreur est "Case sans select Case"
Merci. YANN



Bonjour
Il faudrait peut-être pouvoir identifier la ligne de l'erreur !
Déprotège ton projet et fais tourner la macro pas à pas en mode debogage.
Cordialement
Pascal

"YANN24" a écrit dans le message de news:


Bonjour,
j'ai un gros Pb. Avant, cette combobox fonctionnait très bien (sauf
l'administrateur, mais c'était pas si grave). Mais j'y ai rajouté "2004",
et
ça plante. Il me met "erreur de compilation dans le module caché :
Userform1". POURQUOI ??
Je vous remercie, car je suis vraiment dans le "caca". Merci de votre
aide.
YANN

Private Declare Function GetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As
Long

Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub CommandButton2_Click()
'si l'utilisateur clique sur Annuler, on quitte.
Unload Me
ThisWorkbook.Close
End Sub

Private Sub UserForm_Initialize()
'empêche l'affichage de la croix de fermeture en utilisant les API
'déclarées en début de module
Dim hwnd As Long
hwnd = FindWindowA("Thunder" & IIf(Application.Version Like "8*", "X",
"D")
& "Frame", Me.Caption)
SetWindowLongA hwnd, -16, GetWindowLongA(hwnd, -16) And &HFFF7FFFF

With Me.ComboBox1
.AddItem "2004"
.AddItem "2005"
.AddItem "2006"
.AddItem "Administrateur"
End With

Me.TextBox1.Visible = False
Me.Label1.Visible = False
End Sub

Private Sub combobox1_Click()
Select Case Me.ComboBox1.Value

Case "2004"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 11 To 16
Sheets(I).Visible = True
Next
For I = 17 To 42
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "2005"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 17 To 29
Sheets(I).Visible = True
Next
For I = 11 To 16
Sheets(I).Visible = xlSheetVeryHidden
Next
For I = 30 To 42
Sheets(I).Visible = xlSheetVeryHidden
ActiveWorkbook.Protect
Unload Me

Case "2006"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 30 To 42
Sheets(I).Visible = True
Next
For I = 11 To 29
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "Administateur"

With Me
.ComboBox1.Visible = False
With .TextBox1
.Visible = True
.SetFocus
End With
.Label1.Visible = True
End With

End Select
End Sub
Private Sub commandbutton1_Click()

If Me.ComboBox1.Value = "" Then
MsgBox "vous n'avez rien saisi"
Me.ComboBox1.SetFocus
Else
If TextBox1.Value = "" Then
Else
If controlmdp(TextBox1.Value) = True Then
ThisWorkbook.IsAddin = False
For I = 1 To ThisWorkbook.Sheets.Count
Sheets(I).Visible = True
Next
Unload Me
End If
End If
End If

End Sub
Function controlmdp(nommdp)
On Error Resume Next
tabmdp = Array("passe")
trouve = Application.WorksheetFunction.HLookup(nommdp, tabmdp, 1, False)
If Err.Number <> 0 Then
Err.Clear
MsgBox "Vous n'êtes pas autoriser à pénétrer cet espace réservé"
Else
MsgBox "Autorisation acceptée"
controlmdp = True
End If
End Function










Avatar
YANN24
Merci, je retest.
Et à ton avis, pourquoi mon administrateur plante ?
Normalement, quand je le sélectionne, il devrait me faire apparaitre la
cellule pour mon mot de passe, mais il ne fait rien. Pourquoi?
Merci.
YANN


bonjour Yann,

il manque un Next à:
Case "2005"
...
For I = 30 To 42
Sheets(I).Visible = xlSheetVeryHidden
'---> ici

isabelle


Re,
le message d'erreur est "Case sans select Case"
Merci. YANN



Bonjour
Il faudrait peut-être pouvoir identifier la ligne de l'erreur !
Déprotège ton projet et fais tourner la macro pas à pas en mode debogage.
Cordialement
Pascal

"YANN24" a écrit dans le message de news:


Bonjour,
j'ai un gros Pb. Avant, cette combobox fonctionnait très bien (sauf
l'administrateur, mais c'était pas si grave). Mais j'y ai rajouté "2004",
et
ça plante. Il me met "erreur de compilation dans le module caché :
Userform1". POURQUOI ??
Je vous remercie, car je suis vraiment dans le "caca". Merci de votre
aide.
YANN

Private Declare Function GetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As
Long

Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub CommandButton2_Click()
'si l'utilisateur clique sur Annuler, on quitte.
Unload Me
ThisWorkbook.Close
End Sub

Private Sub UserForm_Initialize()
'empêche l'affichage de la croix de fermeture en utilisant les API
'déclarées en début de module
Dim hwnd As Long
hwnd = FindWindowA("Thunder" & IIf(Application.Version Like "8*", "X",
"D")
& "Frame", Me.Caption)
SetWindowLongA hwnd, -16, GetWindowLongA(hwnd, -16) And &HFFF7FFFF

With Me.ComboBox1
.AddItem "2004"
.AddItem "2005"
.AddItem "2006"
.AddItem "Administrateur"
End With

Me.TextBox1.Visible = False
Me.Label1.Visible = False
End Sub

Private Sub combobox1_Click()
Select Case Me.ComboBox1.Value

Case "2004"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 11 To 16
Sheets(I).Visible = True
Next
For I = 17 To 42
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "2005"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 17 To 29
Sheets(I).Visible = True
Next
For I = 11 To 16
Sheets(I).Visible = xlSheetVeryHidden
Next
For I = 30 To 42
Sheets(I).Visible = xlSheetVeryHidden
ActiveWorkbook.Protect
Unload Me

Case "2006"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 30 To 42
Sheets(I).Visible = True
Next
For I = 11 To 29
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "Administateur"

With Me
.ComboBox1.Visible = False
With .TextBox1
.Visible = True
.SetFocus
End With
.Label1.Visible = True
End With

End Select
End Sub
Private Sub commandbutton1_Click()

If Me.ComboBox1.Value = "" Then
MsgBox "vous n'avez rien saisi"
Me.ComboBox1.SetFocus
Else
If TextBox1.Value = "" Then
Else
If controlmdp(TextBox1.Value) = True Then
ThisWorkbook.IsAddin = False
For I = 1 To ThisWorkbook.Sheets.Count
Sheets(I).Visible = True
Next
Unload Me
End If
End If
End If

End Sub
Function controlmdp(nommdp)
On Error Resume Next
tabmdp = Array("passe")
trouve = Application.WorksheetFunction.HLookup(nommdp, tabmdp, 1, False)
If Err.Number <> 0 Then
Err.Clear
MsgBox "Vous n'êtes pas autoriser à pénétrer cet espace réservé"
Else
MsgBox "Autorisation acceptée"
controlmdp = True
End If
End Function













Avatar
isabelle
je ne voie pas, que veut tu dire par :
quand je le sélectionne, il devrait me faire apparaitre la
cellule pour mon mot de passe
quelle cellule ?

une cellule est sur une feuille normalement

Case "Administateur"
With Me
.ComboBox1.Visible = False
With .TextBox1
.Visible = True
.SetFocus
End With
.Label1.Visible = True
End With

isabelle


Merci, je retest.
Et à ton avis, pourquoi mon administrateur plante ?
Normalement, quand je le sélectionne, il devrait me faire apparaitre la
cellule pour mon mot de passe, mais il ne fait rien. Pourquoi?
Merci.
YANN



bonjour Yann,

il manque un Next à:
Case "2005"
...
For I = 30 To 42
Sheets(I).Visible = xlSheetVeryHidden
'---> ici

isabelle



Re,
le message d'erreur est "Case sans select Case"
Merci. YANN




Bonjour
Il faudrait peut-être pouvoir identifier la ligne de l'erreur !
Déprotège ton projet et fais tourner la macro pas à pas en mode debogage.
Cordialement
Pascal

"YANN24" a écrit dans le message de news:



Bonjour,
j'ai un gros Pb. Avant, cette combobox fonctionnait très bien (sauf
l'administrateur, mais c'était pas si grave). Mais j'y ai rajouté "2004",
et
ça plante. Il me met "erreur de compilation dans le module caché :
Userform1". POURQUOI ??
Je vous remercie, car je suis vraiment dans le "caca". Merci de votre
aide.
YANN

Private Declare Function GetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As
Long

Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub CommandButton2_Click()
'si l'utilisateur clique sur Annuler, on quitte.
Unload Me
ThisWorkbook.Close
End Sub

Private Sub UserForm_Initialize()
'empêche l'affichage de la croix de fermeture en utilisant les API
'déclarées en début de module
Dim hwnd As Long
hwnd = FindWindowA("Thunder" & IIf(Application.Version Like "8*", "X",
"D")
& "Frame", Me.Caption)
SetWindowLongA hwnd, -16, GetWindowLongA(hwnd, -16) And &HFFF7FFFF

With Me.ComboBox1
.AddItem "2004"
.AddItem "2005"
.AddItem "2006"
.AddItem "Administrateur"
End With

Me.TextBox1.Visible = False
Me.Label1.Visible = False
End Sub

Private Sub combobox1_Click()
Select Case Me.ComboBox1.Value

Case "2004"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 11 To 16
Sheets(I).Visible = True
Next
For I = 17 To 42
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "2005"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 17 To 29
Sheets(I).Visible = True
Next
For I = 11 To 16
Sheets(I).Visible = xlSheetVeryHidden
Next
For I = 30 To 42
Sheets(I).Visible = xlSheetVeryHidden
ActiveWorkbook.Protect
Unload Me

Case "2006"
ThisWorkbook.IsAddin = False
ActiveWorkbook.Unprotect
For I = 30 To 42
Sheets(I).Visible = True
Next
For I = 11 To 29
Sheets(I).Visible = xlSheetVeryHidden
Next
ActiveWorkbook.Protect
Unload Me

Case "Administateur"

With Me
.ComboBox1.Visible = False
With .TextBox1
.Visible = True
.SetFocus
End With
.Label1.Visible = True
End With

End Select
End Sub
Private Sub commandbutton1_Click()

If Me.ComboBox1.Value = "" Then
MsgBox "vous n'avez rien saisi"
Me.ComboBox1.SetFocus
Else
If TextBox1.Value = "" Then
Else
If controlmdp(TextBox1.Value) = True Then
ThisWorkbook.IsAddin = False
For I = 1 To ThisWorkbook.Sheets.Count
Sheets(I).Visible = True
Next
Unload Me
End If
End If
End If

End Sub
Function controlmdp(nommdp)
On Error Resume Next
tabmdp = Array("passe")
trouve = Application.WorksheetFunction.HLookup(nommdp, tabmdp, 1, False)
If Err.Number <> 0 Then
Err.Clear
MsgBox "Vous n'êtes pas autoriser à pénétrer cet espace réservé"
Else
MsgBox "Autorisation acceptée"
controlmdp = True
End If
End Function