I've been at this for hours with google sending me to obsolete and older code that no longer works for office 2013. *sigh ![Mad :mad: :mad:](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Ok, so I have a simple request. I need to look in Dir$("P:\path"), find most recent file of "Internal-EOM-201*" & ".xlsx", open it and define it for later reference.
This bit of code seems the most likely candidate to what I need to do, but application.filesearch no longer works past 2007 apparently. Now I'm stuck.
I don't need anything fancy, the path won't ever change and the starting file name won't ever change. Just need to always open the most recent file or if none is present (it gets archived once a week), return MsgBox "No report found".
Ok, so I have a simple request. I need to look in Dir$("P:\path"), find most recent file of "Internal-EOM-201*" & ".xlsx", open it and define it for later reference.
This bit of code seems the most likely candidate to what I need to do, but application.filesearch no longer works past 2007 apparently. Now I'm stuck.
Code:
With Application.FileSearch .NewSearch
.LookIn = "P:\path"
.Filename = "Internal-EOM-201*" & ".xlsx"""
If .Execute(SortBy:=msoSortByLastModified, SortOrder:=msoSortOrderDescending) > 0 Then
For i1 = 1 To .FoundFiles.Count
Workbooks.Open (.FoundFiles(i1))
Next i1
End If
End With
I don't need anything fancy, the path won't ever change and the starting file name won't ever change. Just need to always open the most recent file or if none is present (it gets archived once a week), return MsgBox "No report found".