Results 1 to 6 of 6

Thread: Moving Multiple Files From One Folder To Another

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    12
    Rep Power
    0

    Moving Multiple Files From One Folder To Another

    hi,
    Please help, I need to move several files to another folder but cannot proceed successfully due to "run time error 53", I am aware that the solution to this will be to delete the content that doesn't exist in the code.
    What I want is for the program to run without encountering the error and without deleting any content in the code. I will be using my macro regularly , checking from a hundred of files(500) and deleting to the code files or content that does not exist will be tedious.
    I am new and still learning/trying to know how to write VBA code.
    Thanks in advance.

    ofel

    My code as follows,
    Code:
    Sub Copy_Payroll_Files()
    Set fso = CreateObject("Scripting.FileSystemObject")    'define shorcut
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    zSourceFolder = "C:\RCI_FILES\SOA\2013\2013_03_AGENTS\"                          'set source folder; include "\" at end
    
    Set fso = CreateObject("Scripting.FileSystemObject")    'define shorcut
    fso.movefile zSourceFolder & "234446500579*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500155*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500676*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500456*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500511*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500391*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500587*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500341*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500309*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500634*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500317*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500480*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500464*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500325*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500260*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500406*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500642*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500090*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500139*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500147*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500197*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500074*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500113*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500684*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500032*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500498*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500799*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500503*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500252*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500715*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500820*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500375*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500294*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500472*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500189*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500163*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500367*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500626*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500765*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500618*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500561*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500707*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500105*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500082*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500016*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500121*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500171*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500202*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500210*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500228*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500244*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500278*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500286*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500333*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500359*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500383*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500414*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500422*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500430*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500448*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500529*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500529*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500595*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500600*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500650*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500668*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500692*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500723*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500731*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500749*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500757*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500773*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500781*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    fso.movefile zSourceFolder & "234446500812*.txt", "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
    
    Set fso = Nothing
    
    End Sub
    Last edited by Excel Fox; 05-09-2013 at 08:25 AM. Reason: Added Code Tags

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    You are sure you want to hard code all these files? Or do you want to have a more generic move-all-available-files macro?
    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

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    12
    Rep Power
    0
    Quote Originally Posted by Excel Fox View Post
    You are sure you want to hard code all these files? Or do you want to have a more generic move-all-available-files macro?
    .
    Hi,
    yes .
    Thanks

  4. #4
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Yes to what??!
    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

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    12
    Rep Power
    0
    Hi,
    Sorry , it is yes for -You are sure you want to hard code all these files?
    my purpose is to segregate/separate and to properly classify these accounts from the others.

    Thanks
    Ofel

  6. #6
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    13
    Maybe something like this
    Code:
    Sub Copy_Payroll_Files()
    zSourceFolder = "C:\RCI_FILES\SOA\2013\2013_03_AGENTS\"
    For Each it In Array("234446500579*.txt", "234446500155*.txt", "234446500676*.txt", "234446500456*.txt", "234446500511*.txt", "234446500391*.txt", "234446500587*.txt", _
                        "234446500341*.txt", "234446500309*.txt", "234446500634*.txt", "234446500317*.txt", "234446500480*.txt", "234446500464*.txt", "234446500325*.txt", _
                        "234446500260*.txt", "234446500406*.txt", "234446500642*.txt", "234446500090*.txt", "234446500139*.txt", "234446500147*.txt", "234446500197*.txt", _
                        "234446500074*.txt", "234446500113*.txt", "234446500684*.txt", "234446500032*.txt", "234446500498*.txt", "234446500799*.txt", "234446500503*.txt", _
                        "234446500252*.txt", "234446500715*.txt", "234446500820*.txt", "234446500375*.txt", "234446500294*.txt", "234446500472*.txt", "234446500189*.txt", _
                        "234446500163*.txt", "234446500367*.txt", "234446500626*.txt", "234446500765*.txt", "234446500618*.txt", "234446500561*.txt", "234446500707*.txt", _
                        "234446500105*.txt", "234446500082*.txt", "234446500016*.txt", "234446500121*.txt", "234446500171*.txt", "234446500202*.txt", "234446500210*.txt", _
                        "234446500228*.txt", "234446500244*.txt", "234446500278*.txt", "234446500286*.txt", "234446500333*.txt", "234446500359*.txt", "234446500383*.txt", _
                        "234446500414*.txt", "234446500422*.txt", "234446500430*.txt", "234446500448*.txt", "234446500529*.txt", "234446500595*.txt", "234446500600*.txt", _
                        "234446500600*.txt", "234446500650*.txt", "234446500668*.txt", "234446500692*.txt", "234446500723*.txt", "234446500731*.txt", "234446500749*.txt", _
                        "234446500757*.txt", "234446500773*.txt", "234446500781*.txt", "234446500812*.txt")
        If Dir(zSourceFolder & it) <> vbNullString Then
            With CreateObject("Scripting.FileSystemObject")
                .movefile zSourceFolder & it, "c:\RCI_FILES\SOA\2013\2013_03_AGENTS\php"
            End With
        End If
    Next
    End Sub
    Last edited by bakerman; 05-10-2013 at 02:00 PM.

Similar Threads

  1. Moving Several Files To Several Folders
    By galang_ofel in forum Excel Help
    Replies: 3
    Last Post: 06-01-2013, 04:21 PM
  2. Save Processed Files Into Different Another Folder
    By DARSHANKmandya in forum Excel Help
    Replies: 1
    Last Post: 03-22-2013, 07:10 PM
  3. Replies: 2
    Last Post: 03-12-2013, 02:57 PM
  4. Replies: 2
    Last Post: 09-24-2012, 09:20 PM
  5. List Of All Files In A Folder
    By Excel Fox in forum Excel Help
    Replies: 2
    Last Post: 10-27-2011, 09:10 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
  •