PDA

View Full Version : Accessing files in order of Date Last modified



adriel_fred
09-27-2012, 11:16 PM
I am trying to copy files from a network drive to a local drive.However in this network drive there are thousands of files which are not needed for me.I have managed to copy only the files which are needed for me based on the file name.However this is taking a very long time as the VBA code which I have written goes through every file in the folder in a random order .The files that I require will be the most recent files at the time of running the macro.So I was wondering if there is any way to force VBA to access the files in the order of date last modified

Simplified Code I am using is as below

For each objFile in ObjFolder.files
If <Filename satisfies filter condition> then
objfile.copy "DestinationFolder"
End if
Next objfile

Now the first file that the for loop accesses should be the latest file in the folder and so on

BrianMH
09-28-2012, 12:04 AM
Not sure if you can do that but you could try using search instead.

http://support.microsoft.com/kb/185476