Hi all
My VBA code currently lists all *.xls files in a directory and displays these in a form listbox.
How can this be modified so that it will also search in subdirectories?
Many thanks for your help,
Russel
My VBA code currently lists all *.xls files in a directory and displays these in a form listbox.
How can this be modified so that it will also search in subdirectories?
Code:
Private Sub UserForm_Initialize()
On Error Resume Next
Dim FileList(), i As Long, X, n As Long, fName As String
FilePath = "C:\Users\Russel\Documents\Projects\"
fName = Dir(FilePath & "*" & SearchBox.Value & "*.xls")
i = 1
Do While fName <> ""
ReDim Preserve FileList(1 To i)
FileList(i) = fName
i = i + 1
fName = Dir()
Loop
ReDim Preserve FileList(1 To i - 1)
With Me.ListBox1
.Clear
.List = FileList
End With
End Sub
Many thanks for your help,
Russel