+ Reply to Thread
Results 1 to 7 of 7

VBA Copying files from one location to another

  1. #1
    Registered User
    Join Date
    05-21-2015
    Location
    England
    MS-Off Ver
    2013
    Posts
    25

    VBA Copying files from one location to another

    Afternoon all,

    I am using the below code (along with some formulas and a UDF) to transfer the latest file in a directory to another location.

    The UDF & Formulas compare the latest filename that was uploaded to the latest file in the source location, the names could be something like this:

    Last Upload - Upload_Data123.csv
    Latest file in source location: Upload_Data124.csv

    So the macro will transfer Upload_Data124.csv into the desired folder.

    However, sometimes the situation could be this:

    Last Upload - Upload_Data123.csv
    Latest file in source location: Upload_Data125.csv

    I need the code to copy all files GREATER than the last upload file across, so it would copy
    Upload_Data124.csv & Upload_Data125.csv

    Here is the code, any help would be appreciated:


    Please Login or Register  to view this content.
    Thanks
    Dan

  2. #2
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: VBA Copying files from one location to another

    Hi Dan,

    That code seems to just copy every path that is in the Insurer List. I can't see any comparison between file names.

    Can you check this is the right code and attach a sample workbook?

  3. #3
    Registered User
    Join Date
    05-21-2015
    Location
    England
    MS-Off Ver
    2013
    Posts
    25
    I have protected the data so i have had to remove some of the formulas but i assure you it searches for a specific file.

    Attached is the example workbook
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    05-21-2015
    Location
    England
    MS-Off Ver
    2013
    Posts
    25

    Re: VBA Copying files from one location to another

    Still struggling with this, so just a friendly bump if anyone has any thoughts?

  5. #5
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: VBA Copying files from one location to another

    Hi Dan,

    Since your bump I have been working on this in little bits of spare time I can find during the day. Hang in there

  6. #6
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: VBA Copying files from one location to another

    Hi Dan,

    I finished this off today on my lunch break. Lots of fun

    Due to the different styles of file counters you'll need to add a few columns to your table which tells the code where to look for the counter (and if it is a date).
    Additionally, the code ignores your "Transfer Required?" column since the formula used was unreliable, and by finding the difference between the file name counters we can infer whether a transfer is required or not.

    The code works with all the file name styles in your sample workbook and works if there are gaps in the incrementation, e.g. if Data123.csv is the last import and Data130.csv is the latest source file, but only Data123.csv, Data125.csv, Data129.csv, and Data130.csv exist, it will import those files that exist and skip the gaps. This is more likely to happen with the date counters of course.
    The code will print the transfer details to the console for information purposes. Example:
    Please Login or Register  to view this content.

    Find my code below. You will need the functions after the main sub, too. Also included at the end are the subs I used to create files / folders to test the code (NB that I set all file extensions to .txt for testing purposes).

    Please Login or Register  to view this content.

    Also attached is the workbook that I used to create / test this.

    Enjoy!
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: VBA Copying files from one location to another

    Hi Dan,

    Have you tried this out? Did it work? Let me know
    If that takes care of your original question, please select Thread Tools from the menu link above to mark this thread as SOLVED.
    To say thanks to the user(s) who contributed towards the solution, you can use the "Add Reputation" button on their helpful post(s).
    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copying Files : Userdefined Location to user defined destination folder
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-15-2016, 05:31 PM
  2. Copying files from one location to another based on list
    By maym in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-28-2016, 08:09 PM
  3. [SOLVED] Open excel files, copy sheet 1 to new location and close original files
    By ghostly1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-08-2015, 11:48 AM
  4. split text files stored in some location to multiple files based on a condition
    By GIRISH_KH in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-01-2013, 11:32 AM
  5. copying files from one location into another.
    By CWinkler in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-01-2011, 11:21 AM
  6. [SOLVED] Copying files from one location into another
    By CWinkler in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-01-2011, 11:20 AM
  7. Saving copying text files named in a column to a different location
    By twills in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-19-2010, 08:44 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1