Private Sub UserForm_Initialize()
Dim Chemin As String, i As Long, m As Long, fs
Dim répertoire As String
With ListView1
With .ColumnHeaders
.Clear
.Add , , "Client", 100
.Add , , "PDF", 250, lvwColumnCenter
End With
.View = lvwReport
.FullRowSelect = True
.Gridlines = True
End With
ActiveCell.EntireRow.Select
TextBox1.Value = ActiveCell.Value
TextBox2.Value = ActiveCell.Offset(0, 1).Value
TextBox3.Value = ActiveCell.Offset(0, 10).Value
m = 1
Application.ScreenUpdating = False
répertoire = ThisWorkbook.Path
' ClasseurMaitre = ThisWorkbook.Name
Set fs = CreateObject("Scripting.FileSystemObject")
Set Dossier = fs.GetFolder(répertoire)
For Each d In Dossier.SubFolders
' sousRépertoire = d.Name
Chemin = Dir(répertoire & "\Offres\")
'Chemin = "S:\Téléchargement\Offres" 'Chemin du répertoire à traiter, à modifier
Set fs = Application.FileSearch
With fs
.LookIn = Chemin
.Filename = "*.pdf" 'filtre uniquement les fichiers pdf
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
If InStr(1, Dir(.FoundFiles(i)), TextBox1.Value) <> 0 Then
ListView1.ListItems.Add , , Dir(.FoundFiles(i)) 'nom du fichier dans la première colonne
ListView1.ListItems(m).SubItems(1) = .FoundFiles(i) 'chemin complet du fichier
m = m + 1
End If
Next
End If
End With
Set fs = Nothing
End Sub