+ Reply to Thread
Results 1 to 6 of 6

Splitting a Text File and importing into multiple excel files

  1. #1
    Registered User
    Join Date
    07-27-2009
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003
    Posts
    7

    Splitting a Text File and importing into multiple excel files

    We have a giant text file that is produced weekly by a computer. This text file contains all of our financial information up to that point in time.

    This text file is ~110,000 lines long, and gets bigger with more contracts, etc. So it isnt possible to just import all of the data at once and then work with it due to the issue of excel capping around 62k lines (addressing I guess).

    The text file is currently turned into 13 separate reports, by hand, on a weekly basis (not all of the file is used). The person that normally does this finds the start of the pertinant data by a label. The label is a single line in the text file that has a name, which becomes the name of the excel file. There would also be something to mark the end of the report, but I still need to figure those out on an individual basis.

    So what I need to do in VBA is:
    1. Open a text file and read it line by line
    2. Create new excel files and write to them

  2. #2
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Splitting a Text File and importing into multiple excel files

    This code snippet should get you started with regards to Opening the text file, and searching for your 'starting' marker:

    Please Login or Register  to view this content.
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  3. #3
    Registered User
    Join Date
    07-27-2009
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Splitting a Text File and importing into multiple excel files

    What is the Variable Type for "wholefile"?

    String Array?
    Last edited by DhavokD; 07-28-2009 at 10:37 AM.

  4. #4
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Splitting a Text File and importing into multiple excel files

    Oops, sorry, it's because in my code I have it declared outside of the sub.
    For you the following should work:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-27-2009
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Splitting a Text File and importing into multiple excel files

    Having issues opening the file....

    Open ThisWorkbook.Path & "\" & "13JULY2009" For Binary As #1
    ReDim filebytes(LOF(1) - 1)
    Get #1, , filebytes
    Close



    The first line gives a "Subscript out of range" error.


    FIXT: .txt helps!
    Last edited by DhavokD; 07-28-2009 at 12:37 PM.

  6. #6
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Splitting a Text File and importing into multiple excel files

    Just read it and was about to ask whether the file had an extension or not

+ 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