+ Reply to Thread
Results 1 to 9 of 9

Macro to open every file in a folder, run a certain macro and close each file.

  1. #1
    Forum Contributor
    Join Date
    11-20-2012
    Location
    stockholm
    MS-Off Ver
    Excel 2010
    Posts
    123

    Macro to open every file in a folder, run a certain macro and close each file.

    Hi

    I have folder with a lot of files. Each one of these files contain a macro called "crunch". Instead of open every file by itself and run the macro I would like to be able to run a macro from a diffrent file that opens each file in the specific folder - runs the "crunch" macro - save the file and close it. I can manage to run a macro in one other file but not step through all files in a folder.

    Anyone having a solution to this?

    Thanks!
    Last edited by masben; 01-13-2013 at 01:04 AM.

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Macro to open every file in a folder, run a certain macro and close each file.

    Hi masben,

    Try this - just change the 'strMyDirectory' variable to suit:

    Please Login or Register  to view this content.
    The only thing is that I couldn't get the macro to run if the macro name was variable which is OK in this case.

    Regards,

    Robert
    Last edited by Trebor76; 01-12-2013 at 02:27 AM.
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Forum Contributor
    Join Date
    11-20-2012
    Location
    stockholm
    MS-Off Ver
    Excel 2010
    Posts
    123

    Re: Macro to open every file in a folder, run a certain macro and close each file.

    Robert,

    This works exactley as I wanted it to do - PERFECT - THANKS!

    Do you know if it's possible to ad like a pop up window when running the macro that asks for the directory and name of the macro to run? I'm very happy with the answer I already got but this would be a nice bonus :-)

    Thanks again,
    Martin

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Macro to open every file in a folder, run a certain macro and close each file.

    Hi Martin,

    See how this goes:

    Please Login or Register  to view this content.
    Regards,

    Robert

  5. #5
    Forum Contributor
    Join Date
    11-20-2012
    Location
    stockholm
    MS-Off Ver
    Excel 2010
    Posts
    123

    Re: Macro to open every file in a folder, run a certain macro and close each file.

    Great!

    This makes the macro useful in many other applications aswell.

    Thank you very much Robert.

    All the best,
    Martin

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Macro to open every file in a folder, run a certain macro and close each file.

    Hi Martin,

    Thanks for the feedback and for adding to my reputation

    I'm glad we were able to provide you with a suitable solution.

    Regards,

    Robert

  7. #7
    Forum Contributor
    Join Date
    11-20-2012
    Location
    stockholm
    MS-Off Ver
    Excel 2010
    Posts
    123

    Re: Macro to open every file in a folder, run a certain macro and close each file.

    Robert - never mind this one..

    I solved it mysef :-)

    //Martin



    Hi again Robert,

    I tried the macro again and it seems like the files that are opened are not closed after the macro has run. Must have missed this when I tried the macro at first.

    Guess this is a pretty easy fix for a guy with your skill :-)

    Thanks,
    Martin
    Last edited by masben; 01-14-2013 at 05:04 AM. Reason: solved it myself..

  8. #8
    Forum Contributor
    Join Date
    11-20-2012
    Location
    stockholm
    MS-Off Ver
    Excel 2010
    Posts
    123

    Re: Macro to open every file in a folder, run a certain macro and close each file.

    Robert,

    Do you know what would be EVEN better? :-) Instead of entering the directory to the files... is it possible to browse the directories at your computer??

    I feel I maybe pushing it but worth asking (and I promise I will add even more to your reputation :-) )

    Thanks again,
    Martin

  9. #9
    Forum Contributor
    Join Date
    11-20-2012
    Location
    stockholm
    MS-Off Ver
    Excel 2010
    Posts
    123

    Re: Macro to open every file in a folder, run a certain macro and close each file.

    Quote Originally Posted by Trebor76 View Post
    Hi Martin,

    Thanks for the feedback and for adding to my reputation

    I'm glad we were able to provide you with a suitable solution.

    Regards,

    Robert
    Hi Robert,

    Would it be possible to instead of entering a directory path - browse your computer and select the directory??

    This might be pushing it - I promise to add even more to your reputation if you fix this :-)

    Thanks (again),
    Martin

+ 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