Option Explicit
Function NbJoursAMJ(ByVal Texte As String) As Double
Dim P As Byte, C As String * 1, Ans As Double, Mois As Double, Jours As Double, Nbr As Long
For P = 1 To Len(Texte)
C = Mid$(Texte, P, 1)
Select Case C
Case "0" To "9": Nbr = 10 * Nbr + C
Case "a": Ans = Ans + Nbr: Nbr = 0
Case "m": Mois = Mois + Nbr: Nbr = 0
Case "j": Jours = Jours + Nbr: Nbr = 0
End Select
Next P
NbJoursAMJ = Int(Jours + (Mois + 12 * Ans) * 48699 / 1600)
End Function
Function TexteAMJ(ByVal Jours As Double) As String
Dim Sép As String, Ans As Integer, Mois As Integer
Mois = Int(Jours * 1600 / 48699 + 2 ^ -5)
Jours = Int(Jours - Mois * 48699 \ 1600)
Ans = Mois \ 12: Mois = Mois Mod 12
If Jours > 0 Then TexteAMJ = Jours & Left$(" jours", (Jours < 2) + 6): Sép = " et "
If Mois > 0 Then TexteAMJ = Mois & " mois" & Sép & TexteAMJ: Sép = IIf(Sép = "", " et ", ", ")
If Ans > 0 Then TexteAMJ = Ans & Left$(" ans", (Ans < 2) + 4) & Sép & TexteAMJ
End Function