Reputation: 1
I need to copy 20+ files, each housed by unique folders, into a single folder.
I created the below code.
I get
Compile Error: Object required.
Folder name is the date of the report (eg. 090118), hence, I decided to use a loop until the end of the month (931). I also added error handling code to skip the holidays and weekends.
Sub CopyFiles()
Dim NewFolder As String
Dim NDay As Long
Dim FileName As String
Dim Month As Variant
Set Month = InputBox("Enter month, eg. 01-January")
NewFolder = "C:\Results\Trading\2018\" & Month & "\Backtest Daily Files\Daily GS\" 'Don't forget to edit this
NDay = 901
On Error Resume Next
Do While NDay < 931
FileName = Dir("C:\Reports\2018\" & Month & "\0" & NDay & "18\GS_Futures*.cs*")
FileCopy FileName, NewFolder
NDay = NDay + 1
Loop
End Sub
Upvotes: 0
Views: 136
Reputation: 111
This might not be the most efficient way, however you could use a loop to select the file and then move it useing copyfile
.
Sub Move_File()
Dim myFSO As Object
Dim startFolder As String, endFolder As String
Dim startFile As String
startFile = "test.xls"
For i = 1 To 20
startFolder = Range(Cells(i,2),Cells(i,2))
endFolder = "C:\Test\"
myFSO.copyfile startFolder & startFile, endFolder & endFile, True
Next i
End Sub
Upvotes: 1