Sub test()
Dim Liste, Folder
Folder = GetOpenFolderName2: If Folder = "" Then Exit Sub
Liste = GetFolderList(Folder)
If IsArray(Liste) Then Cells(2, 1).Resize(UBound(Liste), 2) = Liste
ActiveWorkbook.Worksheets("Feuil1").ListObjects("Tableau1").Sort.SortFields. _
Add Key:=Range("Tableau1[[#All],[Nom AO]]"), SortOn:=xlSortOnValues, Order _
:=xlAscending, DataOption:=xlSortNormal
End Sub
'la boite de dialogue de selection du dossier maitre
Function GetOpenFolderName2() As String
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then GetOpenFolderName2 = .SelectedItems(1)
End With
End Function
'la fonction renvoie un tableau des noms des dossier(si il y en a )
Function GetFolderList(FolderParent) As Variant
'patricktoulon:developpez.com
Dim t(), a&, P$
P = Dir(FolderParent & "\", vbDirectory)
Do While P <> ""
If (GetAttr(FolderParent & "\" & P) = vbDirectory) And Left(P, 1) <> "." Then
a = a + 1: ReDim Preserve t(1 To 2, 1 To a): t(1, a) = P
If IsDate(Left(P, 10)) Then t(2, a) = CDate(Left(P, 10))
End If
P = Dir
Loop
If a > 0 Then GetFolderList = Application.Transpose(t)
End Function