File-search results in worksheet
Put your string in cell A1 and run:
Sub ListFiles()
Dim s As String
s = Range("A1").Value
s2 = "*" & s & "*.*"
With Application.FileSearch
.NewSearch
.LookIn = "C:"
.SearchSubFolders = True
.Filename = s2
.FileType = msoFileTypeAllFiles
If .Execute() 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
ActiveSheet.Cells(i + 1, 1).Value = _
.FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
1. the code is adapted from a Tom Ogilvy posting
2. it takes a long time to run (at least on my old computer)
--
Gary's Student
"hmm" wrote:
I need a formula for Excel whose input is a string, and whose output is a
list of path\filename found for filenames containing the string.
|