Hi to all,
I have here a working code that will search and display files matching a certain string in a directory (.e.g. "Structural analysis.pdf") . However, I can't get around to have it search in sub-directories as well. Unfortunately, i'm just a beginner with excel vba, can someone help me ? I would like it to show the path to the files as well if possible. Thanks a lot and appreciate it !!
JCC
************************************
Sub ListFiles()
Dim MyFolder As String
Dim MyFile As String
Dim j As Integer
MyFolder = Cells(2, 4)
MyFile = Dir(MyFolder & "\*structural analysis*.pdf")
Do While MyFile <> ""
j = j + 5
Cells(j, 4).Value = MyFile
MyFile = Dir
Loop
MyFolder = Cells(2, 4)
MyFile = Dir(MyFolder & "\*geotech*.pdf")
Do While MyFile <> ""
j = j + 1
Cells(j, 4).Value = MyFile
MyFile = Dir
Loop
MyFolder = Cells(2, 4)
MyFile = Dir(MyFolder & "\*inspection*.pdf")
Do While MyFile <> ""
j = j + 1
Cells(j, 4).Value = MyFile
MyFile = Dir
Loop
End Sub
********************************************
Bookmarks