This should get you started. I have a sheet that includes the
following ranges:
"Path" - a single cell where I type in the path to the files
"FileSpec" - a single cell where I type in the qualifier such as
"*.xls"
"FileList" - a dynamic range where the list of file names is placed.
The macro creates a list of the files in the folder and then creates
hyperlinks to each of them. Not exactly what you are looking for but a
start.
- John Michl
www.JohnMichl.com
==================================================
Sub ListFiles()
Dim p As String ' path
Dim s As String ' specifier
Dim r As Integer ' row number
Dim i As Integer 'index number
Dim l As Integer ' length of path
p = ActiveSheet.Range("Path").Value
s = ActiveSheet.Range("FileSpec").Value
r = 8
l = Len(p) + 2
' Clear previous file list if any - cell A8 is top of list
If ActiveSheet.Range("A8") < "" Then
ActiveSheet.Range("FileList").Clear
ActiveSheet.Range("FileList").Hyperlinks.Delete
End If
With Application.FileSearch
.NewSearch
.LookIn = p
.Filename = s
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
ActiveSheet.Cells(r, 1).Value = Mid(.FoundFiles(i),
l, 100)
r = r + 1
Next i
For Each cell In ActiveSheet.Range("FileList")
cell.Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection,
Address:=p & "\" & cell.Value _
, TextToDisplay:=cell.Value
Next cell
Else
MsgBox "There were no files found matching the criteria."
End If
End With
End Sub