Results 1 to 14 of 14

Thread: Split Text File Into Multiple Text Files keeping the header row

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    441
    Location
    Should be able to attach up to 2mb zip file. However, posted lines are enough to test with.

    Consider:
    ...
    Dim strH As String
    ...
        Set TSRead = FSO.OpenTextFile(inputFile)
        strH = TSRead.readline & vbCrLf
        strH = strH & TSRead.readline & vbCrLf
    ...
                TSWrite.Write strH & Join(outputLines, vbCrLf)
    ...
            TSWrite.Write strH & Join(outputlines2, vbCrLf)
    ...
    If you really don't want to include line 1 in subsequent pages, that gets a bit more complicated. Consider:
    ...
    Dim strH1 As String, strH2 As String
    ...
        Set TSRead = FSO.OpenTextFile(inputFile)
        strH1 = TSRead.readline & vbCrLf
        strH2 = TSRead.readline & vbCrLf
    ...
                TSWrite.Write IIf(part = 1, strH1, "") & strH2 & Join(outputLines, vbCrLf)
    ...
            TSWrite.Write strH2 & Join(outputlines2, vbCrLf)
    ...
    Last edited by June7; 09-20-2023 at 02:27 PM.
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •