Public Sub Sample()
Dim TargetPath As String
Dim TargetFile As String
TargetPath = "C:\Users\XXXX\Documents"
TargetFile = "Book1.xlsx"
Cells.ClearContents
Cells(1, 1).Value = "ファイル存在の有無"
Cells(1, 2).Value = "検索したフォルダ"
Call FSearch(TargetPath, TargetFile)
End Sub
|
Public Sub FSearch(TargetPath As String, TargetFile As String)
Dim FSO
Dim sFolder
Dim myRow As Long
Dim buf As String
Set FSO = CreateObject("Scripting.FileSystemObject")
For Each sFolder In FSO.GetFolder(TargetPath).SubFolders
myRow = Cells(Rows.Count, 2).End(xlUp).Row + 1
buf = Dir(sFolder.Path & "\" & TargetFile)
If buf <> "" Then
Cells(myRow, 1).Value = "〇"
End If
Cells(myRow, 2).Value = sFolder.Path
Call FSearch(sFolder.Path, TargetFile)
Next sFolder
End Sub
|