daniel1949
XLDnaute Occasionnel
Bonjour le forum,
Je n'arrive pas à inscrire des chiffres en format € dans un textBox de formulaire.
J'ai essayé :
TextBox2 = VBA.Format(TextBox2.Value, " 0.00 €")
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox2.Value = Format(Replace(TextBox2.Value, ".", ","), "#0.00 €")
End Sub
Private Sub TextBox2_Change()
TextBox2.Value = Replace(TextBox2.Value, ".", ",")
TextBox2.Value = Format(TextBox2.Value, "0#.00 €")
End Sub
Private Sub TextBox2_Change()
On Error Resume Next
TextBox2 = Replace(TextBox2, ".", ",")
If Not IsNumeric(TextBox2) Then
TextBox2.Text = Left(TextBox2, Len(TextBox2) - 1)
End If
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox2
If IsNumeric(.Text) Then
TextBox2.Text = Format(TextBox2.Text, "# ###.00 €")
End If
End With
End Sub
----------------------------------------------------------------------------------------
Private Function FormatEuro(ByVal Txt As String) As String
Txt = Replace(Replace(Replace(Txt, ".", ","), " €", ""), " ", "")
FormatEuro = Format(CDbl(Txt), "### ### ##0.00 €")
End Function
Private Sub TextBox2_AfterUpdate()
TextBox2.Text = FormatEuro(TextBox2.Text)
TextBox2.SelStart = Len(TextBox2.Value) – 1
End Sub
----------------------------------------------------------------------------------------
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = CheckLaSaisie(TextBox2, KeyAscii)
End Sub
----------------------------------------------------------------------------------------
Function CheckLaSaisie(Textbox As MSForms.Textbox, ByVal Char As Integer)
Dim SepDec As String
SepDec = Application.International(xlDecimalSeparator)
If Char = 44 Or Char = 46 Then
If InStr(1, Textbox, SepDec, vbTextCompare) > 0 Then
CheckLaSaisie = 0
Else
CheckLaSaisie = Asc(SepDec)
End If
Else
If Char < 48 Or Char > 58 Then
CheckLaSaisie = 0
Else
CheckLaSaisie = Char
End If
End If
End Function
--------------------------------------------------------------------------------
Et bien d'autres encore sans résultat.
Merci de bien vouloir vous pencher sur mon problème.
Bonne journée.
Daniel
NB : Je suis sous Vista. Il s'agit d'un TextBox de formulaire et non USF.
Je n'arrive pas à inscrire des chiffres en format € dans un textBox de formulaire.
J'ai essayé :
TextBox2 = VBA.Format(TextBox2.Value, " 0.00 €")
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox2.Value = Format(Replace(TextBox2.Value, ".", ","), "#0.00 €")
End Sub
Private Sub TextBox2_Change()
TextBox2.Value = Replace(TextBox2.Value, ".", ",")
TextBox2.Value = Format(TextBox2.Value, "0#.00 €")
End Sub
Private Sub TextBox2_Change()
On Error Resume Next
TextBox2 = Replace(TextBox2, ".", ",")
If Not IsNumeric(TextBox2) Then
TextBox2.Text = Left(TextBox2, Len(TextBox2) - 1)
End If
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox2
If IsNumeric(.Text) Then
TextBox2.Text = Format(TextBox2.Text, "# ###.00 €")
End If
End With
End Sub
----------------------------------------------------------------------------------------
Private Function FormatEuro(ByVal Txt As String) As String
Txt = Replace(Replace(Replace(Txt, ".", ","), " €", ""), " ", "")
FormatEuro = Format(CDbl(Txt), "### ### ##0.00 €")
End Function
Private Sub TextBox2_AfterUpdate()
TextBox2.Text = FormatEuro(TextBox2.Text)
TextBox2.SelStart = Len(TextBox2.Value) – 1
End Sub
----------------------------------------------------------------------------------------
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = CheckLaSaisie(TextBox2, KeyAscii)
End Sub
----------------------------------------------------------------------------------------
Function CheckLaSaisie(Textbox As MSForms.Textbox, ByVal Char As Integer)
Dim SepDec As String
SepDec = Application.International(xlDecimalSeparator)
If Char = 44 Or Char = 46 Then
If InStr(1, Textbox, SepDec, vbTextCompare) > 0 Then
CheckLaSaisie = 0
Else
CheckLaSaisie = Asc(SepDec)
End If
Else
If Char < 48 Or Char > 58 Then
CheckLaSaisie = 0
Else
CheckLaSaisie = Char
End If
End If
End Function
--------------------------------------------------------------------------------
Et bien d'autres encore sans résultat.
Merci de bien vouloir vous pencher sur mon problème.
Bonne journée.
Daniel
NB : Je suis sous Vista. Il s'agit d'un TextBox de formulaire et non USF.
Dernière édition: