Option Explicit
'Const mask = "**.**.**.**.**"
'Const mask = "--.--.--.--.--"
'Const mask = "__.__.__.__.__"
Const mask = "__ __ __ __ __"
'Const mask = "==.==.==.==.=="
'Const mask = ".. .. .. .. .."
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim V$, X&, SL&
With TextBox1
V = .Value: If V = "" Then V = mask
X = .SelStart: SL = .SelLength
Select Case KeyCode
Case 96 To 105 ' les touches du pavé
Select Case X: Case 2, 5, 8, 11: X = X + 1: SL = SL - 1: SL = IIf(SL < 1, 1, SL): End Select
If X = 14 Then KeyCode = 0: Exit Sub
Mid(V, X + 1, SL) = mask: Mid(V, X + 1, 1) = Chr(KeyCode - 48)
KeyCode = 0: .Value = V
Select Case X: Case 1, 4, 7, 10: X = X + 1: SL = IIf(SL < 1, 1, SL - 1): End Select
.SelStart = X + 1
Case 8
If X < 1 Then KeyCode = 0: Exit Sub
Select Case X: Case 3, 6, 9, 12: X = X - 1: End Select
KeyCode = 0: Mid(V, X, 1) = Mid(mask, X, 1)
If V = mask Then V = ""
.Value = V: .SelStart = X - 1
Case 46
Case 13, 9
case else :keycode=0
End Select
End With
End Sub