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 36
| Type M_A
Mois As String
Annee As Integer
Trouve As Boolean
End Type
Sub test()
Dim a As M_A
a = MoiAnnee("Janvier2014")
If a.Trouve = False Then MsgBox "pas cool"
a = MoiAnnee("Janvier 2014")
If a.Trouve = False Then MsgBox "pas cool"
a = MoiAnnee("Janvier-2014")
If a.Trouve = False Then MsgBox "pas cool"
a = MoiAnnee("Janvier_2014")
If a.Trouve = False Then MsgBox "pas cool"
Debug.Print "Mois:= " & a.Mois & " Année:= " & a.Annee
End Sub
Function MoiAnnee(V) As M_A
Dim T
Dim t2
t2 = V
T = Array("", "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre", False)
For I = 1 To 12
If InStr(UCase(Trim("" & V)), UCase(T(I))) <> 0 Then Exit For
Next
If T(I) <> False Then
MoiAnnee.Mois = "" & T(I)
t2 = Replace(t2, T(I), "")
t2 = Replace(t2, "-", "")
t2 = Replace(t2, "_", "")
MoiAnnee.Annee = CInt(t2)
MoiAnnee.Trouve = True
End If
End Function |
Partager