+ Reply to Thread
Results 1 to 10 of 10

VBA macro that copy files from multiple subfolders

  1. #1
    Registered User
    Join Date
    02-07-2016
    Location
    Canada
    MS-Off Ver
    13
    Posts
    65

    Exclamation VBA macro that copy files from multiple subfolders

    Hi everyone,
    I have a VBA for copying images from one folder to another based on image names. You can check macro in work in attached. Code is:

    Please Login or Register  to view this content.


    However, I need 2 more things to add to this code:
    1. When I enter the name of the file to be copied, I also want to copy files that have the same name PLUS extension _01/_02/.../_07 if those exist.
    2. I want macro to look not only inside specified folder but also in subfolders inside the folder and subfolders inside the subfolder etc.

    Can anyone help?
    Thanks!
    Attached Files Attached Files
    Last edited by alansidman; 02-07-2016 at 09:26 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,937

    Re: VBA macro that copy files from multiple subfolders

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: VBA macro that copy files from multiple subfolders

    Hi..

    You could maybe use this.. adapt/blend it.. it will do the main part which is finding/moving the files..

    The command window will pop open often.. but if that doesn't worry you..

    mmm.. can't post the code.. Succuri firewall issue..

    Check the attached text file..
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    02-07-2016
    Location
    Canada
    MS-Off Ver
    13
    Posts
    65

    Re: VBA macro that copy files from multiple subfolders

    Thanks a lot! I've tried to change path but it gives me an error...

  5. #5
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: VBA macro that copy files from multiple subfolders

    k.. i actually tested this one..

    It worked fine here.. so lets start debugging..

    Have you stepped through the code in the VB Editor(F8)?.. if so.. what line gives the error and what exactly is the error message?

  6. #6
    Registered User
    Join Date
    02-07-2016
    Location
    Canada
    MS-Off Ver
    13
    Posts
    65

    Re: VBA macro that copy files from multiple subfolders

    Private Sub CommandButton1_Click()

    Completer error: Sub or Function not defined

    I tried to delete "Private" and leave Sub only - still the same... What do you think it can be?

  7. #7
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: VBA macro that copy files from multiple subfolders

    oops.. OPtion Explicit..

    I forgot to Dim the y variable as a Variant

    Replace the first line with:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    02-07-2016
    Location
    Canada
    MS-Off Ver
    13
    Posts
    65
    Quote Originally Posted by apo View Post
    oops.. OPtion Explicit..

    I forgot to Dim the y variable as a Variant

    Replace the first line with:

    Please Login or Register  to view this content.
    Still no...

  9. #9
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: VBA macro that copy files from multiple subfolders

    Still no...
    Sorry.. but you need to be more specific/detailed in your replies..

    Perhaps attach the Workbook that you have added my code to and also explain in detail the folder/file structure you are using to test it with..

    Like i say.. it works in the test i did.. using dummy values like apple, pear,banana and then having files in folders (and sub folders) like apple, apple_01, apple_04, banana, banana_02... etc

    All files that were found were moved to dest folder for me..

  10. #10
    Registered User
    Join Date
    02-07-2016
    Location
    Canada
    MS-Off Ver
    13
    Posts
    65

    Re: VBA macro that copy files from multiple subfolders

    Hi! I'm new to it...
    I attached the file with macro.
    The error is - "Sub is not defined". Is there a way to fix it please?
    Thank you!
    Attached Files Attached Files

+ 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] list of subfolders in folder - without files and sub-subfolders
    By MartyZ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2022, 10:56 AM
  2. 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
  3. Macro Code to Encrypt Multiple Excel Files in Folders and Subfolders
    By ali_1989 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2014, 12:53 PM
  4. [SOLVED] Files within Multiple SubFolders and SubFolders Within It
    By codeslizer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-18-2013, 04:18 AM
  5. copy files from subfolders
    By tryer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-08-2012, 05:53 PM
  6. import multiple html files from multiple and subfolders
    By wali in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-04-2011, 04:33 PM
  7. copy subfolders, replace text in files and save files in copied subfolders
    By pieros in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-01-2005, 09:05 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