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 30 31 32 33 34 35
| Sub testx()
MsgBox date_en_lettres(Date)
MsgBox date_en_lettres("15/06/1985")
End Sub
'
Function date_en_lettres(dat)
date_en_lettres = nblettres(Day(dat)) & Format(dat, " mmmm ") & nblettres(Year(dat))
End Function
Function nblettres(x)
x = Format(x, "0000")
Dim Mil&, Cen&, Dix&, mm$, CC$, N$
unit = Array("", "un", "deux", "trois", "quatre", "cinq", "six", "sept", "huit", "neuf", "dix", "onze", "douze", "treize", "quatorze", "quinze", "seize", "dix-sept", "dix-huit", "dix-neuf")
unitdix = Array("", "dix", "vingt", "trente", "quarante", "cinquante", "soixante", "soixante-dix", "quatre-vingt", "quatre-vingt-dix")
mm = " mille": CC = " cent": Et = ""
'base de controle des segements
Mil = Val(Left(x, 1)): Cen = Val(Mid(x, 2, 1)): Diz = Val(Mid(x, 3, 1)): U = Val(Right(x, 1)): Dix = Val(Mid(x, 3, 2))
If Mil = 0 Then mm = "" 'si moins que mille mm=""
If Mil = 1 Then Mil = 0 'pour eviter d'avoir "mille mille"
If Cen = 0 Then CC = "" 'si moins que cent cc=""
If Cen = 1 Then Cen = 0 'pour eviter d'avoir "cent cent"
If Dix < 20 Then Diz = 0: U = Val(Mid(x, 3, 2)) 'si la tranche des dizaine est moins que 200 diz=0et u =la tranche dizaine (de 11 à 19)
If Dix Mod 10 <> 0 Then Et = "-" ' un tiret sit pas de dizaine ronde
If Dix > 20 And Dix < 80 And Val(Right(U, 1)) = 1 Then Et = " et " 'pour 21,31,41 etc... jusqu'a 71
If Dix > 70 And Dix < 80 Or Dix > 90 Then Diz = Diz - 1: U = U + 10
If Val(Right(x, 3)) < 10 Then Et = ""
If Dix < 20 Then Et = ""
N = unit(Mil) & mm & " " & unit(Cen) & CC & " " & unitdix(Diz) & Et & unit(U) & S
If Right(x, 2) = "80" Or Right(x, 2) = "20" And Val(Right(x, 3)) > 200 Then N = N & "s"
nblettres = N
End Function |
Partager