Salut a toutes et tous,
Voila j'ai trouvé ce code sur le forum (Et j'en remercie l'auteur), qui
sert
a mettre le format téléphone dans un TextBox.
Dim Arriere As Boolean
Const SeparateurTextbox2 = " "
Const NbrDeSeparateursTextbox2 = 4
Const CaracteresPermis = "0123456789"
Private Sub TextBox2_Change()
'Entrée progressive d'un numéro de téléphone "00 00 00 00 00"
Dim i, SuiteDeCaracteres, texte, separateur
If Arriere = True Then
Arriere = False
Exit Sub
End If
If TextBox2.SelStart <> Len(TextBox2.Text) Then
Exit Sub
End If
For i = 1 To Len(TextBox2.Text)
If InStr(CaracteresPermis, Mid(TextBox2.Text, i, 1)) Then
SuiteDeCaracteres = SuiteDeCaracteres + 1
texte = texte & Mid(TextBox2.Text, i, 1)
Else
SuiteDeCaracteres = 0
separateur = separateur + 1
texte = texte & Mid(TextBox2.Text, i, 1)
End If
Next i
If separateur < NbrDeSeparateursTextbox2 Then
If SuiteDeCaracteres = 2 Then
texte = texte & SeparateurTextbox2
End If
End If
TextBox2.Value = texte
End Sub
Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer) 'Telephone
If KeyCode = 8 Then
Arriere = True
End If
End Sub
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Telephone
A = Chr(KeyAscii)
If InStr(SeparateurTextbox2 & CaracteresPermis, A) = 0 Then
KeyAscii = 0
End If
End Sub
Ma question est : Comment je pourrais faire pour l'utiliser sur
plusieurs texbox (6 dans mon cas), afin de ne pas allourdire le code en
répétant 6 fois la même chose.
J'ai tenté avec des variables donnat le nom des TextBox, et en
remplacant dans le code les endroit des noms du TextBox2 par ces variables
mais en vain.
Je vous remercie par avance pour votre aide, Ouille
Salut a toutes et tous,
Voila j'ai trouvé ce code sur le forum (Et j'en remercie l'auteur), qui
sert
a mettre le format téléphone dans un TextBox.
Dim Arriere As Boolean
Const SeparateurTextbox2 = " "
Const NbrDeSeparateursTextbox2 = 4
Const CaracteresPermis = "0123456789"
Private Sub TextBox2_Change()
'Entrée progressive d'un numéro de téléphone "00 00 00 00 00"
Dim i, SuiteDeCaracteres, texte, separateur
If Arriere = True Then
Arriere = False
Exit Sub
End If
If TextBox2.SelStart <> Len(TextBox2.Text) Then
Exit Sub
End If
For i = 1 To Len(TextBox2.Text)
If InStr(CaracteresPermis, Mid(TextBox2.Text, i, 1)) Then
SuiteDeCaracteres = SuiteDeCaracteres + 1
texte = texte & Mid(TextBox2.Text, i, 1)
Else
SuiteDeCaracteres = 0
separateur = separateur + 1
texte = texte & Mid(TextBox2.Text, i, 1)
End If
Next i
If separateur < NbrDeSeparateursTextbox2 Then
If SuiteDeCaracteres = 2 Then
texte = texte & SeparateurTextbox2
End If
End If
TextBox2.Value = texte
End Sub
Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer) 'Telephone
If KeyCode = 8 Then
Arriere = True
End If
End Sub
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Telephone
A = Chr(KeyAscii)
If InStr(SeparateurTextbox2 & CaracteresPermis, A) = 0 Then
KeyAscii = 0
End If
End Sub
Ma question est : Comment je pourrais faire pour l'utiliser sur
plusieurs texbox (6 dans mon cas), afin de ne pas allourdire le code en
répétant 6 fois la même chose.
J'ai tenté avec des variables donnat le nom des TextBox, et en
remplacant dans le code les endroit des noms du TextBox2 par ces variables
mais en vain.
Je vous remercie par avance pour votre aide, Ouille
Salut a toutes et tous,
Voila j'ai trouvé ce code sur le forum (Et j'en remercie l'auteur), qui
sert
a mettre le format téléphone dans un TextBox.
Dim Arriere As Boolean
Const SeparateurTextbox2 = " "
Const NbrDeSeparateursTextbox2 = 4
Const CaracteresPermis = "0123456789"
Private Sub TextBox2_Change()
'Entrée progressive d'un numéro de téléphone "00 00 00 00 00"
Dim i, SuiteDeCaracteres, texte, separateur
If Arriere = True Then
Arriere = False
Exit Sub
End If
If TextBox2.SelStart <> Len(TextBox2.Text) Then
Exit Sub
End If
For i = 1 To Len(TextBox2.Text)
If InStr(CaracteresPermis, Mid(TextBox2.Text, i, 1)) Then
SuiteDeCaracteres = SuiteDeCaracteres + 1
texte = texte & Mid(TextBox2.Text, i, 1)
Else
SuiteDeCaracteres = 0
separateur = separateur + 1
texte = texte & Mid(TextBox2.Text, i, 1)
End If
Next i
If separateur < NbrDeSeparateursTextbox2 Then
If SuiteDeCaracteres = 2 Then
texte = texte & SeparateurTextbox2
End If
End If
TextBox2.Value = texte
End Sub
Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer) 'Telephone
If KeyCode = 8 Then
Arriere = True
End If
End Sub
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Telephone
A = Chr(KeyAscii)
If InStr(SeparateurTextbox2 & CaracteresPermis, A) = 0 Then
KeyAscii = 0
End If
End Sub
Ma question est : Comment je pourrais faire pour l'utiliser sur
plusieurs texbox (6 dans mon cas), afin de ne pas allourdire le code en
répétant 6 fois la même chose.
J'ai tenté avec des variables donnat le nom des TextBox, et en
remplacant dans le code les endroit des noms du TextBox2 par ces variables
mais en vain.
Je vous remercie par avance pour votre aide, Ouille