Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
PhoneBox TextBox1, KeyCode
End Sub
Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
PhoneBox TextBox2, KeyCode
End Sub
Private Sub PhoneBox(TxtB As MSForms.TextBox, ByVal KeyCode As MSForms.ReturnInteger)
'Collection textbox formatés 2022
Dim Mask, X, L
With TxtB
X = .SelStart
L = .SelLength: If L = 0 Then L = 1
If .Value = "" Then .Value = "__ __ __ __ __": Mask = .Value: .SelStart = X Else Mask = .Value
Select Case KeyCode
Case 96 To 105, 48 To 57
If KeyCode < 96 Then KeyCode = KeyCode + 48
If X = 14 Then KeyCode = 0: Exit Sub
If Mid(Mask, X + 1, 1) = " " Then X = X + 1
Mid(Mask, X + 1, 1) = Chr(KeyCode - 48)
KeyCode = 0
Case 8:
If X = 1 Then KeyCode = 0: .Value = "": Exit Sub
If Mid(Mask, X, 1) = " " Then X = X - 1
Mid(Mask, X, 1) = "_": KeyCode = 0: X = X - 2
Case 9, 13
Case Else: KeyCode = 0
End Select
.Value = Mask
If X > 0 Then If Mid(Mask, X + 2, 1) = " " Then X = X + 1
.SelStart = X + 1
.SelLength = L - 1
End With
End Sub