List Files Created Between Two Dates in a single directory (no subfolders)

jey_sea

New Member
Joined
Apr 23, 2010
Messages
24
Hi, I was wondering if someone out there has VBA code to search a directory and list the names of files created between two dates? It would be much appreciated.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Possible with the filesystemobject. Tomorrow I can give you an example, or wait for someone else to jump in?
 
Upvote 0
Here it is:

VBA Code:
Sub JEC()
   c00 = "C:\Users\xxx\Downloads\"
   Ldate = DateSerial(2021, 8, 5)            'set your lower date boundary
   Udate = DateSerial(2021, 8, 27)           'set your upper date boundary
   Set xfolder = CreateObject("scripting.filesystemobject").getfolder(c00).Files
   ReDim ar(xfolder.Count, 1)
   
   For Each it In xfolder
      If Int(it.datecreated) >= Ldate And Int(it.datecreated) <= Udate Then
        ar(x, 0) = it
        ar(x, 1) = Int(it.datecreated)
        x = x + 1
      End If
   Next
         
   Sheets(1).Cells(1).Resize(x, 2) = ar
End Sub
 
Last edited:
Upvote 0
You can also use power query to do this
 
Upvote 0
Sub JEC() c00 = "C:\Users\xxx\Downloads\" Ldate = DateSerial(2021, 8, 5) 'set your lower date boundary Udate = DateSerial(2021, 8, 27) 'set your upper date boundary Set xfolder = CreateObject("scripting.filesystemobject").getfolder(c00).Files ReDim ar(xfolder.Count, 1) For Each it In xfolder If Int(it.datecreated) >= Ldate And Int(it.datecreated) <= Udate Then ar(x, 0) = it ar(x, 1) = Int(it.datecreated) x = x + 1 End If Next Sheets(1).Cells(1).Resize(x, 2) = ar End Sub
JEC, Thankyou very much for the VBA code, it works very fast; again much appreciated!
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,915
Members
448,532
Latest member
9Kimo3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top