+ Reply to Thread
Results 1 to 12 of 12

VBA to search recursively

  1. #1
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    VBA to search recursively

    My macro below checks if the files listed in column A exist in the source folder. If they do then it moves them to the destination folder. Source and destination folder paths are input via message box prompts.

    Please Login or Register  to view this content.

    It works fine , but only searches the top level of the Source folder , and not within its sub-directories.

    Can someone suggest a modification to the code so it searches the source folder recursively , perhaps with an extra Yes / No prompt?

    Grateful for any advice.

    Last edited by CDandVinyl; 04-02-2023 at 01:42 PM.
    Using Excel , Word and Access 2003 - For the whole of 2024

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA to search recursively


    See this thread

  3. #3
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: VBA to search recursively

    Thanks Marc L. I can see this advises the topic , but not sure where it resolves the question of practical implementation into the code above.


  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA to search recursively


    As even if you prefer to use the slower FSO the recursive logic is exactly the same and you can see the samples using it within this forum.

  5. #5
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: VBA to search recursively

    Thanks again Marc L. I was hoping to adapt the existing code rather than re-write , if possible.
    Last edited by CDandVinyl; 04-01-2023 at 10:38 PM.

  6. #6
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: VBA to search recursively

    Quote Originally Posted by CDandVinyl View Post
    1. macro ... checks if the files listed in column A exist in the source folder
    2. If they don't then it moves them to the destination folder

    If a file from column "A" does not exist in the "Source" directory, how can it be moved from this "Source" directory to the "Destination" directory ?
    So, what directory are these files from ?

  7. #7
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: VBA to search recursively

    Hi mjr veverka - Sorry that's a typo. It should read :

    "My macro below checks if the files listed in column A exist in the source folder. If they *do* then it moves them to the destination folder."

    I'll amend accordingly.


  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: VBA to search recursively


    Quote Originally Posted by CDandVinyl View Post
    Thanks again Marc L. I was hoping to adapt the existing code rather than re-write
    Yes like you can find in the samples using FSO (instead of the faster VBA way instead of the fastest Windows way)

  9. #9
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: VBA to search recursively

    Quote Originally Posted by CDandVinyl View Post
    it searches the source folder recursively
    "Recursion" is not needed here, an appropriate approach to the results of certain system commands (e.g. attrib, dir, robocopy, xcopy) from the DOS era is enough.
    Last edited by mjr veverka; 04-02-2023 at 02:23 PM.

  10. #10
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: VBA to search recursively

    Ok thanks guys. I'm afraid I'm not at all familiar with the methods you suggest but I'm grateful for your input.

  11. #11
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: VBA to search recursively


    For example (this is just an example, not a solution) ... "textual variant" - in column 'A' only filenames:
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: VBA to search recursively

    mjr veverka I'm sorry if my original request remains unclear. I'm grateful for your example script.

+ 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. Metadata and music files, recursively. Please help a newbie!
    By Crazyred in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2021, 12:33 PM
  2. Recursively add copy worksheet
    By antros48 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-26-2018, 09:09 AM
  3. Recursively Scan And Open All CSV Files In Directory
    By jo15765 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-17-2018, 06:01 AM
  4. Recursively search a sharepoint site for xls and xlsx files
    By Keruck in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2013, 09:29 AM
  5. Need help recursively copy/pasting
    By TheRaptMuse in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 08-07-2012, 11:35 AM
  6. Recursively matching sums?
    By michaelswhitehe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-28-2006, 10:17 AM
  7. Running an add-in recursively on embedded files
    By akullen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-17-2006, 05:26 PM

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