cs_Marathon Man
Messages postés71Date d'inscriptionlundi 24 juillet 2006StatutMembreDernière intervention 6 septembre 2006
-
1 sept. 2006 à 19:05
cs_Marathon Man
Messages postés71Date d'inscriptionlundi 24 juillet 2006StatutMembreDernière intervention 6 septembre 2006
-
1 sept. 2006 à 22:57
Bonjour à tous,
Je voudrais éxécuter une feuille d'identification automatiquement à l'ouverture d'un classeur.
On peut imaginer deux champs avec le nom et le prénom et s' ils ne correspondent pas
à une liste alors il y a un message et l'écran reste sur la feuille.
mortalino
Messages postés6786Date d'inscriptionvendredi 16 décembre 2005StatutMembreDernière intervention21 décembre 201118 1 sept. 2006 à 19:28
Salut Marathon Man,
essaie ça :
<small>
Coloration syntaxique automatique </small>
' *** dans le module ThisWorkBook :
Private Sub ThisWorkBook_Open()
UserForm1.Show
End Sub
' *** insère un UserForm (UserForm1):
' met lui 2 textbox : (TextBox1 pour le nom, TextBox2 pour le prénom)
' met lui 2 boutons : (CommandButton1 pour valider, CommandButton2 pour annuler)
Private Sub CommandButton1_Click()
If TextBox1.Text = "Man" And TextBox2.Text = "Marathon" Then
MsgBox "Identification connue": Sheets(2).Select
ElseIf TextBox1.Text = "Mortalino" And TextBox2.Text = "" Then
MsgBox "Cette fois ci je ne t'aiderai pas pendant 11h": Sheets(3).Select
Else
MsgBox "Perdu, mauvaise identification": ThisWorkBook.Close False
End If
End Sub
Private Sub CommandButton2_Click()
MsgBox "Vous avez annulé, ce fichier va se fermer": ThisWorkBook.Close False
End Sub
cs_Marathon Man
Messages postés71Date d'inscriptionlundi 24 juillet 2006StatutMembreDernière intervention 6 septembre 2006 1 sept. 2006 à 20:18
Je ne pense pas àvoir fait une erreur mais l'UserForm ne s'affiche pas
et il est bien créé
tu as une idée ?
voilà le code que j'ai mis
Private Sub ThisWorkBook_Open()
UserForm1.Show
End Sub
Private Sub CommandButton1_Click() If TextBox1.Text "Man" And TextBox2.Text "Marathon" Then
MsgBox "Identification connue": Sheets(2).Select ElseIf TextBox1.Text "Mortalino" And TextBox2.Text "" Then
MsgBox "Cette fois ci je ne t'aiderai pas pendant 11h": Sheets(3).Select
Else
MsgBox "Perdu, mauvaise identification": ThisWorkbook.Close False
End If
End Sub
Private Sub CommandButton2_Click()
MsgBox "Vous avez annulé, ce fichier va se fermer": ThisWorkbook.Close False
Vous n’avez pas trouvé la réponse que vous recherchez ?
mortalino
Messages postés6786Date d'inscriptionvendredi 16 décembre 2005StatutMembreDernière intervention21 décembre 201118 1 sept. 2006 à 20:18
Oui, l'idéal serait de placer ta liste dans une feuille de ton classeur :
Par exemple tu la nommes "ListID"
Place dans les cellules :
A1 : Nom
B1 : Prénom
A2:Ax : autant de noms que tu souhaites.
B2:Bx : autant de prénoms que tu souhaites.
<small>
Coloration syntaxique automatique </small>
' *** dans le module ThisWorkBook :
Private Sub ThisWorkBook_Open()
UserForm1.Show
End Sub
' *** insère un UserForm (UserForm1):
' met lui 2 textbox : (TextBox1 pour le nom, TextBox2 pour le prénom)
' met lui 2 boutons : (CommandButton1 pour valider, CommandButton2 pour annuler)
Private Sub CommandButton1_Click()
Dim i As Long, DerLine As Long
For i = 2 To DerLine
If TextBox1.Text = Cells(i, 1).Value And TextBox2.Text = Cells(i, 2).Value Then
MsgBox "Identification connue": Sheets(2).Select: Exit Sub
End If
Next i
MsgBox "Mauvaise identification", vbCritical: TextBox1.SetFocus
End Sub
Private Sub CommandButton2_Click()
MsgBox "Vous avez annulé, ce fichier va se fermer": ThisWorkBook.Close False
End Sub
<small>
Coloration syntaxique automatique </small>
<small></small> @++
<hr size="2" width="100%" />
--Mortalino--
Le mystérieux chevalier, "Provençal, le Gaulois"
<!--
mortalino
Messages postés6786Date d'inscriptionvendredi 16 décembre 2005StatutMembreDernière intervention21 décembre 201118 1 sept. 2006 à 20:24
Il faut absolument que l'objet précédant .Show soit indiqué par son nom.
Par exemple, quand tu insères un UserForm dans un nouveau Projet, il s'appelle UserForm1.
Tu peux le renommer, par exemple en frmPatiente.
Du coup, l'instruction devient :
frmPatiente.Show
@++
<hr size="2" width="100%" />
--Mortalino--
Le mystérieux chevalier, "Provençal, le Gaulois"
<!--
For i = 2 To DerLine
If TextBox1.Text = Cells(i, 1).Value And TextBox2.Text = Cells(i, 2).Value Then
MsgBox "Identification connue": Sheets(2).Select: Exit Sub
End If
Next i
MsgBox "Mauvaise identification", vbCritical: TextBox1.SetFocus
End Sub
Private Sub CommandButton2_Click()
MsgBox "Vous avez annulé, ce fichier va se fermer": ThisWorkBook.Close False
End Sub
For i = 2 To DerLine
If TextBox1.Text = Sheets("ListID").Cells(i, 1).Value And _
TextBox2.Text = Sheets("ListID").Cells(i, 2).Value Then
MsgBox "Identification connue": Sheets(2).Select: Exit Sub
End If
Next i
MsgBox "Mauvaise identification", vbCritical: TextBox1.SetFocus
End Sub
Private Sub CommandButton2_Click()
MsgBox "Vous avez annulé, ce fichier va se fermer": ThisWorkBook.Close False
End Sub
Avant les Cells(i, j), j'aivais oublié 'Sheets("ListID").'
^^ les code là est bon.