'===================================
Function chiffrelettre(s, dvise) 'Trouvé sur ExceLabo
'Modifié (s => la somme en chiffre), (dvise => la devise du pays)JPV
' étant fait par excelabo, ça m'évite de devoir cogiter pour le faire
Dim A As Variant, gros As Variant
Dim Sp As Variant, Chaine$
Dim centime As Double
'Dim Lg%, Gp%, K%, X As Long, c As Long, D As Long
Dim Devise$
'---------------------------------
Devise = dvise '"Euro"
Select Case dvise
Case "€": Devise = "Euro"
Case "$": Devise = "USD"
Case "£": Devise = "GBP"
End Select
'---------------------------------
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", Devise, "billion", _
"milliard", "million", "mille", Devise)
Sp = Space(1)
Chaine = "00000000000000"
'-------- Nouvelle Calédonie pas de Centime --------
If Devise = "CFP" Then
centime = 0
s = Format(s, "## ###,##0 [$" & "CFP" & "-1]")
Else
centime = s * 100 - (Int(s) * 100)
End If
'---------------------------------------------------
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 = Devise & Sp: GoTo Fin
If T <> "" And C = "" And D = "un" Then mydz = "un " & Devise & Sp: GoTo Fin
If T <> "" And T2 = "" And C & D = "" Then mydz = "d'" & Devise & 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
D = A(centime)
If T <> "" Then myct = IIf(centime = 1, " centime", " centimes")
If T = "" Then myct = IIf(centime = 1, " centime d'" & Devise, " centimes d'" & Devise)
If centime = 0 Then D = "": myct = ""
chiffrelettre = T & D & myct
End Function
'============================================