File Searches

P

Paul Gurdin

I want to be able to search for all excel and word files
on my computer and capture the file path, the file name,
date last modified and file size. Is this easy to do? Does
anyone have a piece of code that already does this? I know
it seems like I am after a free bit of code and for
someone to do the work for me, but I really do not know
where to start with this.

Many thanks for any support you can give.
 
R

Ron de Bruin

Try this one

See the help for FileType


Sub Test2()
Dim i As Long
With Application.FileSearch
.NewSearch
.LookIn = "c:\Data"
.SearchSubFolders = False
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
If .Execute(msoSortOrderDescending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
Cells(i, 1).Value = .FoundFiles(i)
Cells(i, 2).Value = FileDateTime(.FoundFiles(i))
Cells(i, 3).Value = FileLen(.FoundFiles(i))
Next i
Else
MsgBox "There were no files found."
End If
End With
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

Top