そのようなことは間違いなく可能です。Excel 2003 以前と同様に、Application.FileSearch を使用して古いバージョンの Excel でこれを行う簡単な方法がありました。2007 以降では、P. Havdra のソリューションを使用または変更する必要があります。
http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/a450830d-4fc3-4f4e-aee2-03f7994369d6/
このスクリプトは、検索パラメーターに一致するファイルのリストを出力し、迷惑なメッセージ ボックスのポップアップも表示します。
作業を開始できるように、彼の FileSearch サブルーチンにいくつかの変更を加えました。これにより、指定したディレクトリに一致する PSD ファイル名の配列が作成され、配列を操作してワークシート データを操作できます。
Sub FileSearch()
'
' Example of FileSearchByHavrda procedure calling as replacement of missing FileSearch function in the newest MS Office VBA
' 01.06.2009, Author: P. Havrda, Czech Republic
'As modified Feb-13-2013, David Zemens, for _
http://stackoverflow.com/questions/14865258/populate-cell-with-a-filename-based-on-path-excerpt-in-previous-cell
'
Dim sDir As String '< this is the search directory you will use
Dim FileNameWithPath As Variant
Dim ListOfFilenamesWithParh As New Collection ' create a collection of filenames
Dim rCount As Long 'row counter
Dim myArray() As Variant
Dim a As Long 'array iterator
a = 0
'Set the search directory:
sDir = "C:\DESKTOP\" '<-- MODIFY TO SUIT YOUR NEEDS
' Filling a collection of filenames (search Excel files including subdirectories)
Call FileSearchByHavrda(ListOfFilenamesWithParh, sDir, "*.psd", False)
' Print list to immediate debug window and as a message window
For Each FileNameWithPath In ListOfFilenamesWithParh ' cycle for list(collection) processing
'Create an array of matching filenames
ReDim Preserve myArray(a)
myArray(a) = FileNameWithPath
a = a + 1
Next FileNameWithPath
' If no file was found:
If ListOfFilenamesWithParh.Count = 0 Then
'Debug.Print "No file was found !"
MsgBox "No file was found !"
Else:
'some files were found, so do something with myArray
'########################################################
'
' <-- Code to manipulate your worksheet will go here -->
'
'
'########################################################
End If
End Sub