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
   | Private Sub partienom_Change()
Dim i As Long, stmessage As String, vs
ListBoxARCHIVES.Clear
nomfeuil = ActiveSheet.Name
vs = Application.Version
If vs < 12 Then
    Set Recherche = Application.FileSearch
Else
    Set Recherche = ClFileSearch.Nouvelle_Recherche
End If
r = ThisWorkbook.Path & "\" & "archives pdf"
With Recherche
    'répertoire pour lancer la recherche
    .FolderPath = r
    'inclu les sous-dossiers dans la recherche
    .SubFolders = True
    'Option de tri:
    '(Sort_None, sort_Name, sort_Path, sort_Size, sort_DateCreated, sort_LastModified, sort_Type)
    'Pas de tri si le paramètre n'est pas spécifié.
    .SortBy = sort_DateCreated
    .Extension = "*" & partienom & "*.pdf"
    'procède à la recherche et capture le nombre de fichiers trouvés
    inombre = .Execute
    stmessage = VBA.Format(inombre, "0"" fichiers trouvés""")
    For i = 1 To .FoundFilesCount
        nom = .Files(i).strfileName
        nom2 = .Files(i).strpathName & "\" & nom
        ListBoxARCHIVES.AddItem nom2 'nom du fichier
    Next i
End With
    If inombre = 0 Then
        MsgBox "0" & " fichier trouvé"
    End If
End Sub | 
Partager