1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| Option Explicit
Dim NbFichiers As Long
Dim TabFichiers() As String
Const TypeFichier As String = "pdf"
Private Sub Liste(sChemin As String, bRecursif As Boolean)
Dim FSO As Object, Dossier As Object
Dim SousDossier As Object, Fichier As String
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Dossier = FSO.GetFolder(sChemin)
Fichier = Dir$(sChemin & "\*.*")
Do While Len(Fichier) > 0
If UCase$(TypeFichier) = UCase$(FSO.GetExtensionName(Fichier)) Then
NbFichiers = NbFichiers + 1
ReDim Preserve TabFichiers(NbFichiers)
TabFichiers(NbFichiers) = Dossier & "\" & Fichier
End If
Fichier = Dir$()
Loop
If bRecursif Then
For Each Dossier In Dossier.SubFolders
Liste Dossier.Path, True
Next Dossier
End If
Set Dossier = Nothing
Set FSO = Nothing
End Sub
Sub SelDossierRacine()
Dim sChemin As String
Dim i As Long
sChemin = ThisWorkbook.Path
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = sChemin & "\"
.Title = "Sélectionner un Dossier"
.AllowMultiSelect = False
.ButtonName = "Sélection Dossier"
.Show
If .SelectedItems.Count > 0 Then
DoEvents
NbFichiers = 0
Erase TabFichiers
Liste .SelectedItems(1), False
End If
End With
End Sub |
Partager