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: