wrote :: 2005.02.01
Sub Sample()
Dim f, buf As String, cnt As Long, FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
With Application.FileSearch
.NewSearch
buf = InputBox("検索するファイル名を指定してください")
If buf = "" Or buf = "False" Then Exit Sub
.Filename = buf
buf = GetFolder("検索を開始するフォルダを指定してください")
If buf = "" Then Exit Sub
.LookIn = buf
.SearchSubFolders = True ''サブフォルダも検索する
If .Execute() > 0 Then
For Each f In .FoundFiles
cnt = cnt + 1
Cells(cnt, 1) = f ''パス+ファイル名
Cells(cnt, 2) = FSO.GetFile(f).Name ''ファイル名
Cells(cnt, 3) = FSO.GetFile(f).ParentFolder ''パス
Next f
Else
MsgBox "見つかりませんでした"
End If
End With
Set FSO = Nothing
End Sub
Function GetFolder(msg As String)
Dim Shell, myPath
Set Shell = CreateObject("Shell.Application")
Set myPath = Shell.BrowseForFolder(&O0, msg, &H1 + &H10)
If Not myPath Is Nothing Then
GetFolder = myPath.Items.Item.Path
Else
GetFolder = ""
End If
Set Shell = Nothing
Set myPath = Nothing
End Function