Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Copy all excel files from one folder to another

Avatar of MPI_IT
MPI_ITFlag for United States of America asked on
Microsoft Excel
16 Comments1 Solution1201 ViewsLast Modified:
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 ?
Thanks !
Sub CopyFilesInFolder()

    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 & "\"
    End If

    Set FSO = CreateObject("scripting.filesystemobject")

    If FSO.FolderExists(FromPath) = False Then
        MsgBox FromPath & " doesn't exist"
        Exit Sub
    End If

    If FSO.FolderExists(ToPath) = False Then
        MsgBox ToPath & " doesn't exist"
        Exit Sub
    End If

    FSO.CopyFile Source:=FromPath & FileExt, Destination:=ToPath
    MsgBox "You can find the files from " & FromPath & " in " & ToPath

End Sub
ASKER CERTIFIED SOLUTION
Avatar of Dave
DaveFlag of Australia image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 16 Comments.
See Answers