I would like to copy all excel files in a folder to another folder using vba code.
I found a vba code which copies excel files from one folder to another, but it does not
copy the files in the subfolders.I will have atleast 2 levels of subfolders .I don't want
to copy the subfolders, only excel files. I have Excel 2007.Any ideas ?
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
FromPath = "C:\L1\Temp\R1"
ToPath = "C:\L2\Temp\R2"
FileExt = "*.xl*"
If Right(FromPath, 1) <> "\" Then
FromPath = FromPath & "\"
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
If FSO.FolderExists(ToPath) = False Then
MsgBox ToPath & " doesn't exist"
FSO.CopyFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "You can find the files from " & FromPath & " in " & ToPath