Bonjour,
un essai :
Sub test()
'Declare the variables
Dim MyPath As String
Dim MyFile As String
Dim idx As Long, listFich() As Variant, fini As Boolean
ReDim listFich(1 To 2, 1 To 1), tmp(2)
'ton répertoir, à modifier en fonction de ce que tu veux
MyPath = "d:\tmp\"
'Make sure that the path ends in a backslash
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
'Get the first Excel file from the folder
MyFile = Dir(MyPath & "*.xls", vbNormal)
'If no files were found, exit the sub
If Len(MyFile) = 0 Then
MsgBox "No files were found...", vbExclamation
Exit Sub
End If
'Loop through each Excel file in the folder
Do While Len(MyFile) > 0
'Assign the date/time of the current file to a variable
idx = idx + 1
ReDim Preserve listFich(1 To 2, 1 To idx)
listFich(1, idx) = FileDateTime(MyPath & MyFile)
listFich(2, idx) = MyFile
'Get the next Excel file from the folder
MyFile = Dir
Loop
' trier tableau dates décroissantes
Stop
Do
fini = True
For idx = 1 To UBound(listFich, 2) - 1
If listFich(1, idx) < listFich(1, idx + 1) Then
tmp(1) = listFich(1, idx)
tmp(2) = listFich(2, idx)
listFich(1, idx) = listFich(1, idx + 1)
listFich(2, idx) = listFich(2, idx + 1)
listFich(1, idx + 1) = tmp(1)
listFich(2, idx + 1) = tmp(2)
fini = False
End If
Next idx
Loop Until fini
'dernier fichier
MsgBox listFich(2, 1)
' avant dernier
MsgBox listFich(2, 2)
' etc
'Workbooks.Open MyPath & LatestFile
End Sub
eric