+ Reply to Thread
Results 1 to 18 of 18

Opening multiple folders consecutively

  1. #1
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Opening multiple folders consecutively

    I have a Macro that performs a variety of tasks on multiple workbooks within a folder and now I need to do this with multiple folders. So I need a loop of sorts to open a folder, then my macro will run, and then move on to another folder, then my macro will run, etc.. I looked online and found many loops for opening multiple files, but have yet to find one that works for multiple folders.

    Please Help

  2. #2
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening multiple folders consecutively

    Can someone please help?

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Opening multiple folders consecutively

    Since you can't open multiple folders in Excel it's not possible to write a macro to do so untill Microsoft change this "restriction" in Excel.

    Alf

  4. #4
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening multiple folders consecutively

    Can you open one at a time and then go to the next one?

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Opening multiple folders consecutively

    Hello bocaj315,

    Yes, you can open the folders one at a time. Are all these folders in a single parent folder or scattered around?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening multiple folders consecutively

    single parent folder

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Opening multiple folders consecutively

    Hello bocaj315,

    That makes it easy. You can use the Dir statement to open parent folder and then the sub-folders. Do you need a code example?

  8. #8
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening multiple folders consecutively

    Yes, that would be great.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Opening multiple folders consecutively

    Hello bocaj315,

    Okay, I write up a loop that open the folders in a parent folder.

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Opening multiple folders consecutively

    Hello bocaj315,

    Here are two macro that work together. The first macro opens all the folders in the parent folder. The second macro opens all the Excel files that have ".xlsm" extensions, modifies them, and closes them. There are only comments added at this time. Once I know what you want to modify, I will change it or you can.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening multiple folders consecutively

    Thanks a bunch! I've modified it a bit because I want to open specific files within the subfolders but it prompts the error message that the document true.xlsx could not be found. I also tried replacing IsFolder where i have changed the font color to SubFolder and this prompted the error that it could not open the file named lots.xlsx. Just to be clear about the structure of my folders: Lots is the parent folder and within lots, there are a bunch of folders all named different things. These are the folders I need to open one by one. Within each one, I have to open a bunch of documents similar to the *_IP.csv I am trying to open here. With this code, the user will save a file to the lots file and then I would use that FilePath as the file path instead of a defined file path
    Please Login or Register  to view this content.
    I really do appreciate your help

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Opening multiple folders consecutively

    Hello bocaj315,

    Can you post the entire macro code that you modified. I am having difficulty matching your comments to the code. Thanks.

  13. #13
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening multiple folders consecutively

    Sure. I have changed the font color of the code you provided me with. So all of the wbSrc workbooks are the workbooks within the subfolders that I will open, I just need help making the loop that tells the computer to go into each subfolder. Hope this helps, let me know if you need any clarifications
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening multiple folders consecutively

    Leith,

    I understand you are very busy but I would really appreciate it if you could assist me. I provided the code you've asked for so if you need anything else, let me know.

  15. #15
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Opening multiple folders consecutively

    Hello bocaj315,

    I will work on correcting your code today. It is clear from the macro you do not understand Dir function, which is why you having so many problems. You should read about this function and learn to use it correctly. Here is a link The Dir Function Explained

  16. #16
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening multiple folders consecutively

    Thanks. You're right, I am still very new to VBA

  17. #17
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening multiple folders consecutively

    You're right, I am still new to VBA. Have you made any progress?

  18. #18
    Registered User
    Join Date
    05-30-2013
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Opening multiple folders consecutively

    Hello Leith,

    Unfortunately I have been unable to figure out a solution. Have you had the opportunity to work on this code at all?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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