Option Explicit
Sub RechDerniersFichiers()
Dim MonRepertoire As String, fso As Object, fs As FileSearch
Dim montableau(), i As Integer, j As Integer, k As Integer, temp
[COLOR="red"][B]Dim monfichier As String[/B][/COLOR]
Set fso = CreateObject("Scripting.FileSystemObject")
Set fs = Application.FileSearch
fs.NewSearch
MonRepertoire = "C:\MesDocuments\Excel"
With fs
.LookIn = MonRepertoire
.Filename = "*.txt"
If .Execute > 0 Then
ReDim montableau(1 To .FoundFiles.Count, 1 To 2)
For i = 1 To .FoundFiles.Count
montableau(i, 1) = .FoundFiles(i)
montableau(i, 2) = fso.GetFile(.FoundFiles(i)).DateLastModified
Next i
End If
End With
For i = LBound(montableau) To UBound(montableau)
For j = LBound(montableau) To UBound(montableau)
If montableau(i, 2) > montableau(j, 2) Then
For k = LBound(montableau, 2) To UBound(montableau, 2)
temp = montableau(i, k)
montableau(i, k) = montableau(j, k)
montableau(j, k) = temp
Next k
End If
Next j
Next i
[B][COLOR="Red"]monfichier = montableau(1, 1)
Workbooks.OpenText monfichier[/COLOR][/B]
End Sub