I would like to use an Excel document with a list of filenames to copy the files listed from multiple folders to one destination folder.
The below code works, however, there are 150 folders and I don't want to have to name each one.
How do I look in all folders in a directory for the files? I was hoping I could replace "O:\96" with "O:*", but wildcards don't appear to work for folders. Most of the folder names are numbers ranging from 10-200, however, some are text.
How can I point the file copy function to all folders on the O drive?
Sub CopyFiles_Fd1_to_Fd2()
Dim i As Long
On Error Resume Next
MkDir "C:\PACKAGED DWGS"
On Error GoTo 0
For i = 1 To 5000
FileCopy "O:\95\" & Sheets(1).Cells(i, 1).Value, "C:\PACKAGED DWGS\" & Sheets(1).Cells(i, 1).Value
On Error Resume Next
FileCopy "O:\96\" & Sheets(1).Cells(i, 1).Value, "C:\PACKAGED DWGS\" & Sheets(1).Cells(i, 1).Value
On Error Resume Next
FileCopy "O:\97\" & Sheets(1).Cells(i, 1).Value, "C:\PACKAGED DWGS\" & Sheets(1).Cells(i, 1).Value
On Error Resume Next
FileCopy "O:\98\" & Sheets(1).Cells(i, 1).Value, "C:\PACKAGED DWGS\" & Sheets(1).Cells(i, 1).Value
On Error Resume Next
Next
End Sub
Microsoft Scripting Runtime 'Companions'
VBE>Tools>References, create a reference toMicrosoft Scripting Runtime.The Code