Saturday, May 27, 2017

Cycle through files in a folder

For example if you are looking for the file "test":

Dir takes wild cards so you could make a big difference adding the filter for test up front and avoiding testing each file


Sub LoopThroughFiles()
    Dim StrFile As String
    StrFile = Dir("c:\testfolder\*test*")
    Do While Len(StrFile) > 0
        Debug.Print StrFile
        StrFile = Dir
    Loop
End Sub

No comments:

Post a Comment