Results 1 to 10 of 100

Thread: Loop Through Files In A Folder Using VBA

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Example Output using " EileensFldr". It can be downloaded from here: https://app.box.com/s/k3m0xfm89msqpoarpx93onyyqupydzk8 Edit Some folder may be missing - alternative see uploaded File
    EileensFldr zip Download.jpg https://imgur.com/f7V2PTL
    By me in Windows that downloads as a .zip File. To use the File, I store it anywhere, then I make a Folder with the name EileensFldr in the same Folder which contains the File in which I place the macros being described here.
    EileensFldr Make Empty Folder.JPG https://imgur.com/6kolxi4
    Then I copy all the files in Folder EileensFldr.zip
    EileensFldr Contents Copy.JPG https://imgur.com/hgqg64w
    And paste into the new Folder which is in the same Folder which contains the File in which I place the macros being described here.
    EileensFldr Contents Paste.JPG https://imgur.com/4qK00eI
    You may have a different method for “unzipping” a “Zipped file”, but the important thing is that you end up with both the File containing the macros and the example File in the same Main Folder.
    Example Folder and Macro File in same Folder.JPG https://imgur.com/LWSUssc
    This requirement is only because of the code line
    Let strWB = ThisWorkbook.Path & "" & "EileensFldr"
    Often such codes are written such that they ask you to select a Folder to be searched through. Here it is simply hardcoded to simplify the demo code.

    Screenshot: EileensFolderExplainedOutput.JPG https://imgur.com/FjjUMYz
    EileensFolderExplainedOutput.jpg

    Using Excel 2007 32 bit
    Main Code Second routine copy 1 Second routine copy 2 Second routine copy 3
    CopyNumber1=1 CopyNumber2=2 CopyNumber3=3 Main first routine, ( Sub( ) ) , starts
    G:\Excel0202015Jan2016\ExcelForum\wbSheetMakerClsd WbADOMsQueery\EileensFldr EileensFldr ( Folder Details of Main Folder are written by Main routine ( Sub( ) ) )
    Main first routine, ( Sub( ) ) , pauses
    G:\Excel0202015Jan2016\ExcelForum\wbSheetMakerClsd WbADOMsQueery\EileensFldr\Fldr1_1 Fldr1_1 First copy of second routine starts
    File1_1a.xlsx
    File1_1b.xlsx
    First copy of second routine pauses
    G:\Excel0202015Jan2016\ExcelForum\wbSheetMakerClsd WbADOMsQueery\EileensFldr\Fldr1_1\Fldr1_1_1 Fldr1_1_1 Second copy of second routine starts
    Second copy of second routine Ends
    G:\Excel0202015Jan2016\ExcelForum\wbSheetMakerClsd WbADOMsQueery\EileensFldr\Fldr1_2 Fldr1_2 First copy of second routine resumes
    File1_2a.xlsx
    File1_2b.xlsx
    File1_2c.xlsx
    First copy of second routine pauses
    G:\Excel0202015Jan2016\ExcelForum\wbSheetMakerClsd WbADOMsQueery\EileensFldr\Fldr1_2\Fldr1_2_1 Fldr1_2_1 Another (Second) copy of second routine starts
    File1_2_1a.xlsx
    File1_2_1b.xlsx
    Second copy of second routine pauses
    G:\Excel0202015Jan2016\ExcelForum\wbSheetMakerClsd WbADOMsQueery\EileensFldr\Fldr1_2\Fldr1_2_1\Fldr1_ 2_1_1 Fldr1_2_1_1 Third copy of second routine starts
    File1_2_1_1a.xlsx
    G:\Excel0202015Jan2016\ExcelForum\wbSheetMakerClsd WbADOMsQueery\EileensFldr\Fldr1_2\Fldr1_2_1\Fldr1_ 2_1_2 Fldr1_2_1_2
    File1_2_1_2a.xlsx
    File1_2_1_2b.xlsx
    Third copy of second routine resumes and Ends
    Second copy of second routine resumes and Ends
    First copy of second routine resumes and Ends
    Main first routine, ( Sub( ) ) , resumes and Ends.
    Yellow indicates code copy currently running: The main code is copied and run once. For the example Folder shown,
    the second routine is copied and run once for the first Folder level, twice for the second level, and once for the third level.
    Worksheet: EFFldr

    See also First Worksheet here:
    https://app.box.com/s/gfuintgifu1hgw5nap3jriz2x8mp911x
    Attached Files Attached Files
    Last edited by DocAElstein; 03-08-2019 at 04:58 PM.

Similar Threads

  1. Replies: 15
    Last Post: 08-23-2013, 12:03 PM
  2. Loop Through And Delete Multiple File Types In A Folder
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 03-30-2013, 04:47 PM
  3. Replies: 2
    Last Post: 03-12-2013, 02:57 PM
  4. Loop through a folder and find word
    By k0st4din in forum Excel Help
    Replies: 7
    Last Post: 12-08-2012, 02:22 PM
  5. Count Files In A Folder VBA
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 05-07-2011, 10:57 PM

Posting Permissions

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