次のコードがあり、横方向にリストされたさまざまなフォルダー内のファイルを取得したいと考えています。列 A の特定のファイル パスに対して、この列のファイルを列 C 以降に取得するように、このコードを修正するにはどうすればよいですか? 私の知識では、1つのフォルダーに対してのみ実行できます(150個のフォルダーではなく)。
`enter code here`
Sub ListFiles()
iCol = 3
Call ListMyFiles(Range("A5"), Range("B5"))
End Sub
Sub ListMyFiles(mySourcePath, IncludeSubfolders)
Set MyObject = New Scripting.FileSystemObject
Set mySource = MyObject.GetFolder(mySourcePath)
On Error Resume Next
For Each myFile In mySource.Files
iRow = 5
Cells(iRow, iCol).Value = myFile.Name
iCol = iCol + 1
Next
If IncludeSubfolders Then
For Each mySubFolder In mySource.SubFolders
Call ListMyFiles(mySubFolder.Path, True)
Next
End If
End Sub