MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Application.filesearch results sorting


Posted by Tim Butler on December 01, 2000 3:24 AM

I'm trying to import files with a macro. The files have names in this format:
***1.xxx
***2.xxx
-
***9.xxx
***10.xxx
The .foundfiles collection returns them sorted by filename as default, i.e.
***1.xxx
***10.xxx
etc. I want them sorted in the order that they were saved. I am trying:

with application.filesearch
.newsearch
if .execute(sortby:=msosortbylastmodified)>0 then
Loadfile
end if
end with

but this invariably returns files sorted by name. Am I missing something? I obviously am. Any pointers deeply appreciated. Ta.


Posted by Andy Ashman on December 04, 2000 8:55 AM

You could try copying the names and creation dates into 2 columns on a worksheet, sorting the worksheet and then reading back the names in order.

Posted by Tim Butler on December 05, 2000 1:20 AM

Andy, thanks for the suggestion, but I managed to solve the problem last night - after 3 days banging my head against the screen. First you filesearch and sort by size. After you have done this you can run a new search and the msoSortByLastModified function works correctly.