1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
Option Explicit
Const entrees_decimales_permises = ".,0123456789" & vbCr & vbBack
Const entrees_entieres_permises = "0123456789" & vbCr & vbBack
Const Point = "."
Const Virgule = ","
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = Asc(Point) Then
If InStr(TextBox1, Virgule) = 0 Then
KeyAscii = Asc(Virgule)
Else
KeyAscii = 0
End If
ElseIf InStr(entrees_decimales_permises, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
ElseIf InStr(TextBox1, Virgule) > 0 And KeyAscii = Asc(Virgule) Then
KeyAscii = 0
End If
If KeyAscii = 13 Then SendKeys "{TAB}": KeyAscii = 0
End Sub
' Saisie entière dans une TextBox
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr(entrees_entieres_permises, Chr(KeyAscii)) = 0 Then KeyAscii = 0
If KeyAscii = 13 Then SendKeys "{TAB}": KeyAscii = 0
End Sub |