This code should help you out. VBA has a built in object for finding files but it doesn't allow you to specify any date ranges. This code uses the FileSystem object. To use it you must click Tools, References and select Microsoft Scripting Runtime otherwise you'll get an error. This is one possible way of many of how to do this. Please let me know if you have any problems.
Sub GetFiles()
Dim dteStart As Date, dteEnd As Date, strFolder As String
Dim fsObj As New Scripting.FileSystemObject, fsFile As Scripting.File
Dim fsFolder As Scripting.Folder, clnExcelFiles As New Collection
On Error GoTo ErrHandler:
'Does not include any error checking e.g. valid path. You'll need to add this.
strFolder = InputBox("Please enter folder path", "Path")
dteStart = InputBox("Please enter start date", "Start date")
dteEnd = InputBox("Please enter end date", "End date")
Set fsFolder = fsObj.GetFolder(strFolder)
For Each fsFile In fsFolder.Files
If fsFile.DateCreated >= dteStart And fsFile.DateCreated <= dteEnd And fsFile.Type = "Microsoft Excel Worksheet" Then
clnExcelFiles.Add fsFile.Name
End If
Next
'the collection clnExcelFiles now includes all Excel files created within the
'specified parameters. You can process them doing something like this:-
For Each i In clnExcelFiles
Workbooks.Open i
'Process the workbook
Next
Exit Sub
ErrHandler:
'An error occured.
End Sub
Thank you Dank, this was a tremendous help!!!
One followup question. Would I need to Dim i As Workbook for that last part to work? Thanks :-)
You don't need to Dim I as workbook because it is actually used to refer to an item in a collection. Dim it as a variant.
Secondly, change the line
clnExcelFiles.Add fsFile.Name
to
clnExcelFiles.Add fsFile.Path
HTH,
Daniel.