+ Reply to Thread
Results 1 to 9 of 9

Compile multiple .log files into a single .txt file

  1. #1
    Registered User
    Join Date
    12-27-2013
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2013
    Posts
    14

    Compile multiple .log files into a single .txt file

    Hello,

    I am looking for VBA code that will allow me to:
    1. Compile all of the .log files in a folder into a single .txt file.
    2. Import that single .txt file into an Excel sheet.

    Currently, I have been using Command Prompt (Windows 7 64-bit) to compile the .log files into a .txt file. Then, I've been manually importing that file into Excel. I was hoping that this could all be done with a single macro.

    Please let me know if there is anymore information I can give that will be helpful (this is my first post) and I will get it asap.

    Thanks in advance^^

  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: Compile multiple .log files into a single .txt file

    Here's a macro for merging all the files of a specified extension (.LOG for you) in a single folder into a single file.

    https://sites.google.com/a/madrocket...-all-txt-files

    Then you can simply open the resulting file in Excel.
    Last edited by JBeaucaire; 12-26-2019 at 05:19 PM.
    _________________
    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
    Registered User
    Join Date
    12-27-2013
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2013
    Posts
    14

    Re: Compile multiple .log files into a single .txt file

    I will give this a shot when I get back this evening.

    Quote Originally Posted by JBeaucaire View Post
    Then you can simply open the resulting file in Excel.
    Does this mean that I cannot use Excel to automatically import the compiled .txt document after it has been created? I was hoping that there could be a single macro that would first compile and then import.

    Thanks a bunch for the quick response!

  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: Compile multiple .log files into a single .txt file

    Yes, you can. It's a single line of code to open a text file in Excel, especially if the filename doesn't change.

    Please Login or Register  to view this content.
    Add that before the END SUB and the last thing that will happen is the created file will be opened.

  5. #5
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Compile multiple .log files into a single .txt file

    Hi..

    I am looking for VBA code that will allow me to:
    1. Compile all of the .log files in a folder into a single .txt file.
    2. Import that single .txt file into an Excel sheet.
    Maybe a slightly different attack can also work..

    1. Build array from all .log files.
    2. Transpose array to sheet.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    12-27-2013
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2013
    Posts
    14

    Re: Compile multiple .log files into a single .txt file

    Quote Originally Posted by JBeaucaire View Post
    Yes, you can. It's a single line of code to open a text file in Excel, especially if the filename doesn't change.

    Please Login or Register  to view this content.
    Add that before the END SUB and the last thing that will happen is the created file will be opened.
    This was fabulous! Exactly what I was asking for and you made it very straightforward for me. Thanks a ton!

  7. #7
    Registered User
    Join Date
    12-27-2013
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2013
    Posts
    14

    Re: Compile multiple .log files into a single .txt file

    Quote Originally Posted by apo View Post
    Hi..



    Maybe a slightly different attack can also work..

    1. Build array from all .log files.
    2. Transpose array to sheet.
    Thanks so much for your response! I will also give your code a shot before the weekend. Hopefully, it can help me understand VBA a little bit better for future use.
    Last edited by phoenixjasper; 08-27-2014 at 01:10 AM. Reason: Tried to avoid clutter.

  8. #8
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Compile multiple .log files into a single .txt file

    You're welcome..

    If you wanted to test it quickly.. you can just download the attached Workbook in my previous post and just Click the button.. browse to the folder that has the .log files.. and the result will be shown in the Workbook.

    Out of interest.. how many lines of data (ball park) are in each of your log files..?

    One of the benefits of using code such as:

    Please Login or Register  to view this content.
    is that it reads ALL of the data from each of your .log files in one go (rather than looping through each line).

    Might make a difference if your log files have heaps of rows..

  9. #9
    Registered User
    Join Date
    12-27-2013
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2013
    Posts
    14

    Re: Compile multiple .log files into a single .txt file

    Your code is fantastic, too! It also worked very easily after I selected the proper folder.

    As far as lines of data, so far it is not that much. A weekly ballpark figure would be between 1000 and1800 lines, but not more than 3000 . That could change if my research project grows in size, so now I have an added option should I be lucky enough for that to happen.

    Thanks very, much for your suggestions and I feel even better about properly (and quickly) preparing my data.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy columns from multiple files into single file
    By kevincoxshall in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-10-2014, 02:39 PM
  2. [SOLVED] How to merge multiple xlsm files into a single file
    By gmatoka in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-18-2012, 07:52 AM
  3. Split single Excel file into multiple files
    By Michael_O in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-21-2012, 06:27 AM
  4. export data from multiple files into a single file
    By graeme00 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-14-2011, 03:07 PM
  5. Replies: 0
    Last Post: 07-31-2006, 07:33 AM

Tags for this Thread

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