Option Explicit
Dim liste$() 'mémorise la variable
Private Sub UserForm_Initialize()
Dim chemin$, fso As Object, f As Object, sf As Object, n&
chemin = ThisWorkbook.Path & "\"
Set fso = CreateObject("Scripting.FileSystemObject")
For Each f In fso.GetFolder(chemin).Files
If InStr("/.bas/.txt/.cls/.frm/", "/" & Right(f.Name, 4) & "/") Then
'ReDim Preserve liste(n) 'initial
ReDim Preserve liste(1 To 2, 1 To n) ' plante ici "l'indice n'appartient pas à la selection" '
'liste(n) = f.Name 'initial
liste(1, n) = f.Name
liste(2, n) = f.Path
n = n + 1
End If
Next f
For Each sf In fso.GetFolder(chemin).SubFolders
For Each f In sf.Files
If InStr("/.bas/.txt/.cls/.frm/", "/" & Right(f.Name, 4) & "/") Then
'ReDim Preserve liste(n) 'initial
ReDim Preserve liste(1 To 2, 1 To n)
'liste(n) = f.Name 'initial
liste(1, n) = f.Name
liste(2, n) = f.Path
n = n + 1
End If
Next f, sf
'If n Then ListBox1.List = liste Else ListBox1.Clear 'initial
If n Then ListBox1.List = Application.Transpose(liste) Else ListBox1.Clear
End Sub