Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Search Files and Report Results in Date Range
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Search for date within a range of dates | Excel Programming | |||
Search All Files Find Newest One Report To Excel 2007 | Excel Programming | |||
Generating a Weekly Report based on a Date Range, where 1 Column = 1 Day | Excel Programming | |||
Sort community search results by date | Excel Programming | |||
Search Range for Criteria in given cell and produce results | Excel Discussion (Misc queries) |