I'm trying to copy files from varies folders(excel files) to one folder. I want it to copy the excel files from those folders, but the folder may or may not exsist and would like to be able to resume to the next on error if the folder doesn't exist. new to vba. Below is essentially what I would like but the loop doesn't work and I want to be able to just search the last 10 folder by the extensions below and if it doesn't exist to go on to the next one and so on until it reaches 10 folders names and copies all the excel files from that folder
Sub Day2()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim i As Integer
For i = 1 To 10
FromPath = "Sample folder\Sample - Submited to TD by Date\" & Format((Now - i), "yyyy") & "\" & Format((Now - i), "yyyy") & "_" & Format((Now - i), "mm") & "\" & _
"Submitted Requests - " & Format((Now - i), "mm") & "-" & Format((Now - i), "dd") & "-" & Format((Now - i), "yy")
ToPath = "\Sample\To Combine\"
FileExt = "*.xl*"
If Right(FromPath, 1) <> "\" Then
FromPath = FromPath & "\"
End If
Set FSO = CreateObject("scripting.filesystemobject")
FSO.CopyFile Source:=FromPath & FileExt, Destination:=ToPath
Next i
End Sub