Hi everyone!
I have a piece of code that was written by someone else (namely Phil_V, from these very forums) that only works in versions of Excel before 2007. I was just hoping that someone could update the code for me?
I know it's a lot to ask, but I simply don't have the expertise to do it myself
I really appreciate any help received.
The code that needs updating is as follows:
Private Sub Find_Newest_Files(ByRef filelist() As Variant)
' Will use the worksheet passed as 'filelist_ws' to compile a list of the newest files in the current directory
Dim l_count As Long
Dim filename As String, place_n_item As String, last_place_n_item As String
Dim fl_index As Long
' Search for all the .txt files files in the current directory that match the filename pattern
With Application.FileSearch <---- This is the part that doesn't work in 2007!!
.NewSearch
.LookIn = ThisWorkbook.Path
.filename = "*-*-*.txt"
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderDescending) > 0 Then
' Resize the array to the largest we will need it
ReDim filelist(1 To .FoundFiles.Count)
fl_index = 0
' Cycle through each of the files that were found
For l_count = 1 To .FoundFiles.Count
' Extract the filename from the foundfile path information
filename = Mid(.FoundFiles(l_count), InStrRev(.FoundFiles(l_count), "\") + 1)
' extract the place and item from the filename
place_n_item = Left(filename, InStrRev(filename, "-") - 1)
' If the place and item are the same as the previous file then this is older, otherwise it's a new file _
and should be added to our filelist array
If place_n_item <> last_place_n_item Then
last_place_n_item = place_n_item
fl_index = fl_index + 1
filelist(fl_index) = .FoundFiles(l_count)
End If
Next
' If we added files to the filelist, then resize the list now to be only as big as we need. _
If we didn't add any files then return the first item in the array as 0.
If fl_index > 0 Then
ReDim Preserve filelist(1 To fl_index)
Else
filelist = [{0}]
End If
Else
filelist = [{0}]
End If
End With
End Sub
Bookmarks