Search a folder for keyword

Viewed 13385

I'm looking to search a folder for a keyword term 'fuel', to pull information from returned files into a 'data' sheet.

For instance, I have a folder week numbers (1 - 52 cross the year so in the new year this will contain one folder but will build as the year goes on).
I search this folder for all .doc files contains the word 'fuel'.
You can do this via a Windows search by typing "fuel" in the search function in the top corner and it will display all filenames and all files that contains the word 'fuel'.

I have this for searching for a file that has 'fuel' in its name, but not inside it.

Sub LoopThroughFiles()
    Dim MyObj As Object, MySource As Object, file As Variant
    file = Dir("c:\testfolder\")
    While (file <> "")
        If InStr(file, "fuel") > 0 Then
            MsgBox "found " & file
            Exit Sub
        End If
        file = Dir
    Wend
End Sub
1 Answers
Related