Set fs = Application.FileSearch 'does not work in 2007

stressman

New Member
Joined
Oct 30, 2011
Messages
10
I have many spreadsheets using the function "file_search" below. The "Set fs = Application.FileSearch" does not work in newer versions of excel. I do not know how to modifiy the function, to get the same results. I think it gives a list of files in the folder picked.
Code:
Sub read_results()
 
Dim initial_folder As String
 
With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Show
        initial_folder = .SelectedItems(1)
End With
 
Dim reluts_file_list As Variant
Dim i As Integer
 
reluts_file_list = file_search(initial_folder, "Analysis_Lug*")
       
…
 
End Sub
 
‘-----------------------------------------------------------------------------------------------------
 
Function file_search(location As String, file_name As String) As Variant
 
Dim file_list As Variant
Dim fs As Variant
Dim i As Integer
 
Set fs = Application.FileSearch     ‘ß----------Does not work in 2007 excel
 
With fs
    .LookIn = location
    .Filename = file_name
    .SearchSubFolders = True
    .MatchTextExactly = True
    If .Execute(SortBy:=msoSortByFileName, _
    SortOrder:=msoSortOrderAscending) > 0 Then
        ReDim file_list(.FoundFiles.Count) As Variant
 
        For i = 1 To .FoundFiles.Count
            file_list(i) = .FoundFiles(i)
        Next i
    Else
 
    End If
 
End With
 
file_search = file_list
 
End Function
 
Last edited by a moderator:

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Watch MrExcel Video

Forum statistics

Threads
1,127,217
Messages
5,623,450
Members
415,970
Latest member
ZorroOP

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top