Sub Test()
Dim Dico As Object
Dim Cle As Variant
Dim Tbl() As String
Dim Tablo(1 To 2)
Dim T
Dim Max As Long
Dim I As Integer
Dim Fichier As String
Dim Chemin As String
'adapter le chemin du dossier !!!!
Chemin = "C:\Users\Ton nom d'utilisateur\Downloads\"
Tbl() = RecupFichiers(Chemin, "xml")
If Not Not Tbl Then
Set Dico = CreateObject("Scripting.Dictionary")
For I = 1 To UBound(Tbl)
T = Split(Tbl(I), ".")
If Not Dico.exists(Right(T(0), 8)) Then
Tablo(1) = T(1): Tablo(2) = Tbl(I)
Dico.Add Right(T(0), 8), Tablo()
Else
If T(1) > Dico(Right(T(0), 8))(1) Then
Dico(Right(T(0), 8))(1) = T(1)
Dico(Right(T(0), 8))(2) = Tbl(I)
End If
End If
Next I
For Each Cle In Dico.Keys
If Cle > Max Then: Max = Cle: Fichier = Dico(Cle)(2)
Next Cle
MsgBox "Le fichier le plus récent est : " & Fichier
End If
End Sub
Function RecupFichiers(Chemin As String, Extension As String) As String()
Dim TableauFichiers() As String
Dim Fichier As String
Dim I As Integer
If Left(Extension, 1) <> "." Then Extension = "." & Extension
Fichier = Dir(Chemin & "*" & "*" & Extension)
Do While (Len(Fichier) > 0)
I = I + 1
ReDim Preserve TableauFichiers(1 To I)
TableauFichiers(I) = Fichier
Fichier = Dir()
Loop
RecupFichiers = TableauFichiers()
End Function