Option Explicit
Dim Wbk As Workbook, Sht As Worksheet
Dim DLig As Long
Sub CompilerFics()
Dim DosSource As String
Set Sht = ThisWorkbook.Sheets("FIC")
' Pour commencer effacer les lignes existantes
If Not Range("L_Com").ListObject.DataBodyRange Is Nothing Then
Range("L_Com").ListObject.DataBodyRange.Delete
End If
DosSource = ThisWorkbook.Path & "\T_projets\"
If DosSource = "" Then Exit Sub
ListerFichiers DosSource, "xlsx", True
Set Sht = Nothing
End Sub
Sub ListerFichiers(DosSource As String, Extension As String, Optional SousFldr = True)
Dim Ind As Integer, TabVal() As String
Dim fso As Object, Dossier As Object
Dim SsRep As Object, Fic As Object
Dim LstR As ListRow
Set fso = CreateObject("Scripting.FileSystemObject")
Set Dossier = fso.GetFolder(DosSource)
For Each Fic In Dossier.Files
If UCase(Right(Fic.Name, 4)) = UCase(Extension) Then
Set LstR = Range("L_Com").ListObject.ListRows.Add
On Error Resume Next
TabVal = Split(Fic.Name, "_")
On Error GoTo 0
For Ind = 0 To UBound(TabVal)
With LstR
.Range(1 + Ind) = TabVal(Ind)
End With
Next Ind
LstR.Range(5).Hyperlinks.Add LstR.Range(5), Fic.Path
End If
Next
End Sub