Hello bodiewil,
You will need to need to use the File System Object to get the last modified date and to recurse the subfolders. Excel 2007 and later no longer uses the Application.FileSearch. The last argument of this macro is a boolean value. True will recurse through all the subfolders of the source folder listing the files and false lists only the files in the source folder.
'Written: March 24, 2010
'Author: Leith Ross
Sub ListFilesInAllFolders(ByVal SourceFolderName As String, ByVal IncludeSubfolders As Boolean)
Dim FSO As Object
Dim SourceFolder As Object
Dim SubFolder As Object
Dim FileItem As Object
Dim R As Long
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = FSO.GetFolder(SourceFolderName)
'Display file properties in columns "A:B" starting at row 1
For Each FileItem In SourceFolder.Files
R = R + 1
Cells(R, "A") = FileItem.Name
Cells(R, "B") = FileItem.DateLastModified
Next FileItem
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFilesInFolder SubFolder.Path, True
Next SubFolder
End If
Columns("A:B").AutoFit
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
End Sub
Calling the macro
Private Sub Searchfile_Click()
ListFilesInAllFolders "C:\Documents and Settings\Owner\My Documents", True
End Sub
Bookmarks