Search Files and Report Results in Date Range

M

MMA-Helper

I have found the code below that performs a search and outputs the results to
column A of a spreadsheet.

I need to modify this code to make 3 changes:
1) prompt the user for the directory of choice
2) prompt the user for a date range of .lastmodified and use that as an
additional search criteria
2) result to list all the files with the directory chosen in column A of the
Excel Workbook

The issue with the current code is that if I choose a path that has
subfolders it comes up "type mismatch" and won't give me the subfolders
information.

My goal is a full directory of all the contents of a path within a certain
date range where edits were made.

Thank you in advance.
-------------------------------
Function CreateFileList(FileFilter As String, _
IncludeSubFolder As Boolean) As Variant
' returns the full filename for files matching
' the filter criteria in the current folder

Dim FileList() As String, FileCount As Long
CreateFileList = ""
Erase FileList
If FileFilter = "" Then FileFilter = "*.*" ' all files
With Application.FileSearch
.NewSearch
.LookIn = "C:\Test\Templates"
.Filename = FileFilter
.SearchSubFolders = IncludeSubFolder
.FileType = msoFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) = 0 Then Exit Function
ReDim FileList(.FoundFiles.Count)
For FileCount = 1 To .FoundFiles.Count
FileList(FileCount) = .FoundFiles(FileCount)
Next FileCount
.FileType = msoFileTypeExcelWorkbooks ' reset filetypes
End With
CreateFileList = FileList
Erase FileList
End Function

Sub TestCreateFileList()
Dim FileNamesList As Variant, i As Integer
' ChDir "C:\My Documents"
' activate the desired startfolder for the filesearch
FileNamesList = CreateFileList("*.*", False)
' performs the filesearch, includes any subfolders
' present the result
Range("A:A").ClearContents
For i = 1 To UBound(FileNamesList)
Cells(i + 1, 1).Formula = FileNamesList(i)
Next i
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

File list - list filenames in excel 4
counting xls files in a folder 8
Update Directory Path in Code 4
Filesearch in 2007 1
Open_Files_In_A_Directory 2
Scan a Directory 5
the '$' in right$() 2
File unable to open 2

Top