re-
avec les adaptations proposées par Dan (non testé)
toujours valable , mettre le premier repertoire en A1 puis lancer la macro
Option Explicit
Sub listefichiers()
Dim aps$, ptrrep&, encours&, repertoire$, nd$, i&, f$
aps = Application.PathSeparator
ptrrep = 1
encours = 1
Do While encours <= ptrrep
repertoire = Cells(encours, 1)
If Right(repertoire, 2) <> "\." Then
On Error Resume Next
nd = Dir(repertoire & aps & "*", vbDirectory)
On Error GoTo 0
Do While nd <> ""
If nd <> ".." Then
ptrrep = ptrrep + 1
Cells(ptrrep, 1) = repertoire & aps & nd
End If
nd = Dir()
DoEvents
Loop
End If
encours = encours + 1
DoEvents
Loop
Range("A1").Resize(ptrrep, 2).Sort key1:=Range("A1"), order1:=xlAscending, Header:=xlNo
For i = ptrrep To 2 Step -1
f = Cells(i, 1)
If Right(f, 2) = aps & "." Then
Cells(i, 1) = Cells(i - 1, 1)
Rows(i).Delete
i = i - 1
Else
Cells(i, 1) = ""
Cells(i, 2) = Mid(f, InStrRev(f, aps) + 1)
End If
Next i
Columns("A:B").AutoFit
MsgBox "terminé"
End Sub