+ Reply to Thread
Results 1 to 7 of 7

how to convert multiple .txt files to .xlsx files using a macro?

  1. #1
    Registered User
    Join Date
    02-21-2013
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    24

    how to convert multiple .txt files to .xlsx files using a macro?

    I have multiple data files with tab delimited data that imports nicely into excel. The problem is that I have MANY of them and need to convert all of them to Excel files for other uses.

    I started by importing one .txt file into excel using tab-delimited conversion which worked perfectly and then saved it as a .xlsx file. I recorded all this by a Macro. Is there a way to use the same macro to convert all the .txt files in a folder or subfolder?

    Below is my VBA macro code. Thanks for the help!

    Please Login or Register  to view this content.

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: how to convert multiple .txt files to .xlsx files using a macro?

    Are all of your text files the EXACT same format?
    Will the excel workbook be in the same directory as those files?
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Registered User
    Join Date
    02-21-2013
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: how to convert multiple .txt files to .xlsx files using a macro?

    All of the files within a folder are in the same format, meaning all tab-delimited .txt files. They have varying numbers of rows.
    The excel workbook can be within the same directory if needed.
    - Thanks!

  4. #4
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: how to convert multiple .txt files to .xlsx files using a macro?

    try the following macro:
    Please Login or Register  to view this content.
    You place it in a module of any workbook. It could be an empty one. It will not be modified by the macro. Or you can place it in your Personnal.xlsb if you want.

  5. #5
    Registered User
    Join Date
    02-21-2013
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: how to convert multiple .txt files to .xlsx files using a macro?

    Worked like a charm! Thanks!

  6. #6
    Registered User
    Join Date
    02-21-2013
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: how to convert multiple .txt files to .xlsx files using a macro?

    One more question... Can the same code be modified to change a series of .csv files to .xlsx by simply changing the "txt" portion to "csv"? Thanks.

  7. #7
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: how to convert multiple .txt files to .xlsx files using a macro?

    CSV files are easier to open in Excel than TXT file.
    Here would be the new macro:
    Please Login or Register  to view this content.
    Regards

    P.S. Do not forget to mark your thread as solved if it is so and please click on the start (on the left side of the grey line) to mark your satisfaction. Thanks

+ 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