+ Reply to Thread
Results 1 to 3 of 3

Macro to copy files from folder and sub-folders fails on sub-folders

  1. #1
    Registered User
    Join Date
    09-01-2022
    Location
    Germantown
    MS-Off Ver
    Office 365
    Posts
    2

    Macro to copy files from folder and sub-folders fails on sub-folders

    I am new to the forum and appreciate any assistance. I have been developing VBA code for about 15 years mostly to automate Word forms to utilize information from databases. I am self taught and have little experience working with VBA in Excel. Now I am trying to create a VBA macro that will copy all .csv files from a primary source folder and, then, loop through all of its sub-folders to copy other .csv files to another target directory that will ultimately be used to import that data into a master workbook. The code is comprised of two subs: the first to copy .csv files from the primary source directory and, the second to copy all of the .csv files from each of the sub-directories. The first sub operates flawlessly and deposits files in the target directory but the code in the second sub does not seem to be able to identify the files in the sub-folders. The code appears to run without error and the message box at the end even tells me that the files have been copied but the files from the sub-directories are not deposited in the target folder. All of the files to be copied periodically have the same naming scheme e.g "SR0097.csv", "SR0098.csv". Microsoft Scripting Runtime is turned on. I am using Office 365 on a Windows 10 machine. I don't believe that this is a permissions or security issue because the first sub works on the primary source folder. I feel like my code needs a small tweak but I can't find it. Thanks in advance for any help you can provide. The code is as follows:
    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

    Thank you.
    Last edited by 6StringJazzer; 09-01-2022 at 02:40 PM.

  2. #2
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: Macro to copy files from folder and sub-folders fails on sub-folders

    Hi jbarryb,
    welcome to the forum.
    Indeed a small tweak (actually 2)
    Please Login or Register  to view this content.
    Cheers
    Eastwood
    I started learning VBA because I was lazy ...
    Still developing.... being more lazy...

  3. #3
    Registered User
    Join Date
    09-01-2022
    Location
    Germantown
    MS-Off Ver
    Office 365
    Posts
    2

    Re: Macro to copy files from folder and sub-folders fails on sub-folders

    Thank you. Mission accomplished.

+ 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. Macro to list all files and folders in sub folders and choose a starting folder
    By LeanAccountant in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-06-2021, 02:04 PM
  2. [SOLVED] Can we use VBA to copy files from folder A to different folders?
    By ec4excel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-16-2021, 02:53 AM
  3. Replies: 5
    Last Post: 11-02-2018, 03:15 AM
  4. Needs macro to copy excel files from folders, subfolders to new folder
    By genetist in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2014, 08:53 AM
  5. Use Excel VBA to Copy multiple files from different source folders to different folders
    By mm1234mail in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2014, 01:17 PM
  6. Replies: 1
    Last Post: 09-12-2013, 09:23 PM
  7. Create folders and move and copy files into that folders
    By vijaybharthi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-31-2010, 04:01 AM

Tags for this Thread

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