Name

Application.FileSearch

Synopsis

(Windows only.) Returns the FileSearch object. The following code displays all of the text files in the current folder:

Sub TestSearch(  ) ' Windows only
    Dim s
    With Application.FileSearch
        .LookIn = ThisWorkbook.Path
        .Filename = ".txt"
        .Execute
        For Each s In .FoundFiles
            Debug.Print s
        Next
    End With
End Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.