Macro à copier dans un module général
Option Explicit
Function chiffrelettre(s)
Dim a As Variant, gros As Variant, sp As String, chaine As String, centime As String
Dim LP As Long, Lg As Long, gp As Long, k As Long, x As String, t As String
Dim d As String, c As String, t2 As String, mydz As String, myct As String
a = Array("", "un", "deux", "trois", "quatre", "cinq", "six", "sept", _
"huit", "neuf", "dix", "onze", "douze", "treize", "quatorze", "quinze", "seize", "dix sept", _
"dix huit", "dix neuf", "vingt", "vingt et un", "vingt deux", "vingt trois", "vingt quatre", _
"vingt cinq", "vingt six", "vingt sept", "vingt huit", "vingt neuf", "trente", "trente et un", _
"trente deux", "trente trois", "trente quatre", "trente cinq", "trente six", "trente sept", _
"trente huit", "trente neuf", "quarante", "quarante et un", "quarante deux", "quarante trois", _
"quarante quatre", "quarante cinq", "quarante six", "quarante sept", "quarante huit", _
"quarante neuf", "cinquante", "cinquante et un", "cinquante deux", "cinquante trois", _
"cinquante quatre", "cinquante cinq", "cinquante six", "cinquante sept", "cinquante huit", _
"cinquante neuf", "soixante", "soixante et un", "soixante deux", "soixante trois", _
"soixante quatre", "soixante cinq", "soixante six", "soixante sept", "soixante huit", _
"soixante neuf", "soixante dix", "soixante et onze", "soixante douze", "soixante treize", _
"soixante quatorze", "soixante quinze", "soixante seize", "soixante dix sept", _
"soixante dix huit", "soixante dix neuf", "quatre-vingts", "quatre-vingt un", _
"quatre-vingt deux", "quatre-vingt trois", "quatre-vingt quatre", "quatre-vingt cinq", _
"quatre-vingt six", "quatre-vingt sept", "quatre-vingt huit", "quatre-vingt neuf", _
"quatre-vingt dix", "quatre-vingt onze", "quatre-vingt douze", "quatre-vingt treize", _
"quatre-vingt quatorze", "quatre-vingt quinze", "quatre-vingt seize", "quatre-vingt dix sept", _
"quatre-vingt dix huit", "quatre-vingt dix neuf")
gros = Array("", "billions", "milliards", "millions", "mille", "euros", "billion", _
"milliard", "million", "mille", "euro")
sp = Space(1)
chaine = "00000000000000"
centime = s * 100 - (Int(s) * 100)
s = Str(Int(s))
Lg = Len(s) - 1
s = Right(s, Lg)
Lg = Len(s)
If Lg < 15 Then chaine = Mid(chaine, 1, (15 - Lg)) Else chaine = ""
s = chaine + s
'billions au centaines
gp = 1
For k = 1 To 5
x = Mid(s, gp, 1)
c = a(Val(x))
x = Mid(s, gp + 1, 2)
d = a(Val(x))
If k = 5 Then
If t2 <> "" And c & d = "" Then mydz = "Euros" & sp: GoTo Fin
If t <> "" And c = "" And d = "un" Then mydz = "un euros" & sp: GoTo Fin
If t <> "" And t2 = "" And c & d = "" Then mydz = "d'euros" & sp: GoTo Fin
If t & c & d = "" Then myct = "": mydz = "": GoTo Fin
End If
If c & d = "" Then GoTo Fin
If d = "" And c <> "" And c <> "un" Then mydz = c & sp & "cents " & gros(k) & sp: GoTo Fin
If d = "" And c = "un" Then mydz = "cent " & gros(k) & sp: GoTo Fin
If d = "un" And c = "" Then myct = IIf(k = 4, gros(k) & sp, "un " & gros(k + 5) & sp): GoTo Fin
If d <> "" And c = "un" Then mydz = "cent" & sp
If d <> "" And c <> "" And c <> "un" Then mydz = c & sp & "cent" + sp
myct = d & sp & gros(k) & sp
Fin:
t2 = mydz & myct
t = t & mydz & myct
mydz = ""
myct = ""
gp = gp + 3
Next k
d = a(centime)
If t <> "" Then myct = IIf(centime = 1, " centime", " centimes")
If t = "" Then myct = IIf(centime = 1, " centime d'euro", " centimes d'euro")
If centime = 0 Then d = "": myct = ""
chiffrelettre = t & d & myct
End Function
Cdlmnt