+ Reply to Thread
Results 1 to 5 of 5

Macro to open and close all files in a folder and sub folders

  1. #1
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Shropshire, England
    MS-Off Ver
    Excel 2007 /10 /13
    Posts
    118

    Macro to open and close all files in a folder and sub folders

    Hi

    I have the following to open all files in a specific folder
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    But want I really need is for it to also look in the sub folders and open all those too, I also would like for it to then close them all.

    Is this something that can be done?

    thanks

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to open and close all files in a folder and sub folders

    Like so, you need a macro to feed in a folder path to the main macro which opens all the files in that path, then searches for folders IN that path and calls itself again, deeper and deeper recursively until it runs out of files/folders. This also shows you one way to close the files you've opened.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 12-24-2012 at 11:41 AM. Reason: Correction
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Shropshire, England
    MS-Off Ver
    Excel 2007 /10 /13
    Posts
    118

    Re: Macro to open and close all files in a folder and sub folders

    Hi JBeaucaire
    Thanks for this, but it doesn't seem to go through the sub-folders, it will cycle through and Excel fils in the top level, but doesn't seem to go into the sub levels

    The set up is around 4 sub folders with about 10 files in each, there are no other sub folders lower down, these 4 all sit in the original top level
    Last edited by BillDoor; 12-24-2012 at 06:17 AM. Reason: additional info

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to open and close all files in a folder and sub folders

    It appears the sub loops were not including the final "/" in the path string, so I added a tweak above in the code to fix that. Tested and working on my system.

  5. #5
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Shropshire, England
    MS-Off Ver
    Excel 2007 /10 /13
    Posts
    118

    Re: Macro to open and close all files in a folder and sub folders

    Hi
    thanks for the reply, hadn't had chance to try it in the last week as have been off work, works a charm though

+ 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