Hello all,
I want to copy data from multiple files from multiple subdirectories. How can I create a loop that searches all subdirectories and opens all files of which the filename contains a certain text?
Right now, my code looks something like this:
Sub Macro1()
path = "C:\"
datafile= Dir(path)
While datafile <> ""
Workbooks.Open (path & datafile)
'some copy/paste-actions
Windows(datafile).Activate
ActiveWindow.Close
datafile= Dir
Wend
End Sub
but it only searches one directory, while my folders look something like this:
C:\folder1\
C:\folder2\
C:\folder2\folder21\
C:\folder2\folder22\
C:\folder3\folder31\folder311\
C:\folder3\folder31\folder312\
C:\folder3\folder31\folder313\folder3131\
C:\folder3\folder31\folder313\folder3132\
etc.
The files are everywhere, some just one subdirectory deep, some 7 or 8. How can I search every directory for every file that meets my criteria? In other words, how can I keep changing my 'path'?
TIA,
Annet
Bookmarks