Results 1 to 10 of 10

Thread: VBA Marco To Copy Excel Files From Sub-Directory To Another Directory

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Try this....

    Code:
    Sub MoveFilesToAnotherFolder()
    
    
        Dim objFSO As Object 'FileSystemObject
        Dim objFile As Object 'File
        Dim objFolder As Object 'Folder
        Const strFolder As String = "C:\pull"
        Const strNewFolder As String = "C:\summary profits"
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        For Each objFolder In objFSO.GetFolder(strFolder & "\").SubFolders
            If Right(objFolder.Name, 2) = "tb" Then
                For Each objFile In objFolder.Files
                    If InStr(1, objFile.Type, "Excel", vbTextCompare) Then
                        Name objFile.Path As strNewFolder & "\" & objFile.Name
                    End If
                Next objFile
            End If
        Next objFolder
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  2. #2
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    14
    Hi Excelfox

    Thanks for the help. When activating the macro, run time error 58 appears "file already exists" and the following code is highlighted

    Name objFile.Path As strNewFolder & "\" & objFile.Name

    It would be appreciated if you could amend your code

Similar Threads

  1. Running a VBA in all excel files
    By msiyab in forum Excel Help
    Replies: 3
    Last Post: 12-26-2012, 01:35 PM
  2. Macro to copy data from a set of excel files
    By Sreejesh Menon in forum Excel Help
    Replies: 5
    Last Post: 11-15-2012, 11:17 AM
  3. Macro for Opening files and copy the contents of the File
    By ravichandavar in forum Excel Help
    Replies: 16
    Last Post: 08-15-2012, 09:17 PM
  4. Send Mail Using VBA In Excel And Attach Files
    By macenmin in forum Excel Help
    Replies: 1
    Last Post: 08-03-2012, 01:03 AM
  5. Replies: 2
    Last Post: 04-08-2012, 09:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •