+ Reply to Thread
Results 1 to 6 of 6

Looping a macro over all files in a folder for a file conversion

  1. #1
    Registered User
    Join Date
    03-09-2011
    Location
    Victoria, British Columbia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Looping a macro over all files in a folder for a file conversion

    Hello there,

    I faced with the task of converting thousands of files with the suffix .asc. These are outputted data files with the standard rows and column of numbers. I would like to be able convert these files into .xls files using a macro. However, I really am not too sure how to loop a macro to run on all files within the folder that the .xls macro file currently resides.

    So for example, if I have C:\Temp with all the .asc files in it and then the .xls macro is within C:\Temp, I would like be able to run the macros to convert all those .asc files into .xls files. Below is a start of some of what I would like done except for this is on a single file. Can anyone recommend a good way to proceed with this?

    Thanks in advance

    Please Login or Register  to view this content.
    Last edited by hippie_dream; 03-10-2011 at 12:11 PM.

  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: Looping a macro over all files in a folder for a file conversion

    Hi, welcome to the forum.

    Be sure to read through the Forum Rules so you can use and follow them effectively. For instance, you'll need to EDIT that post above and put code tags around that code you used. (Like shown in my signature)

    Go ahead and fix that post above and I'll post back a version of your posted macro that loops through all the .asc files in the folder and outputs a matching XLS file.
    _________________
    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 Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Looping a macro over all files in a folder for a file conversion

    Try this, of course I had nothing to test it on...
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 03-09-2011 at 10:10 PM. Reason: Corrected macro

  4. #4
    Registered User
    Join Date
    03-09-2011
    Location
    Victoria, British Columbia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Looping a macro over all files in a folder for a file conversion

    Wow thank you so much.

    Is there any way that I can modify this such that, it search only within the file path that the macros worksheet is in and outputs the .xls files in that same folder? A more general statement? I could also do this manually...

    Thanks again so much!

    Please Login or Register  to view this content.

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

    Re: Looping a macro over all files in a folder for a file conversion

    Something like:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    03-09-2011
    Location
    Victoria, British Columbia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Looping a macro over all files in a folder for a file conversion

    Thanks so much!

+ 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