Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Apr 2001
    Location
    Arriving Somewhere but not Here
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts

    split text file into 2 or more files (Word 2000 on

    I have a series of csv files that I wish to split into two (or more) files. Attached is an dummy example to give an idea of the file structure. From that I think you'll see where I'd like to split the file and end up with three smaller ones.

    I have limited experience of Excel VBA but none of Word VBA, can someone begin to teach me how I'd create a macro to break up a file like this? My searching in the Lounge drew a blank but the answer must be out there somewhere. I may yet resort to XL to do what I want but it's high time I got my feet wet with Word VBA.

    thanks,

    stuck
    Attached Files Attached Files

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: split text file into 2 or more files (Word 200

    One possibility is to import the entire file into a string array using a double paragraph break as your separator, and then to write each array element out to a new text file. This would use VBA's Split() function and the FileSystemObject's file access methods. It would be the same in Word and Excel, since no Word or Excel methods would be used.

    You also could open the document into Word and use Word's text handling methods to select the text to be written out to a new file. If the parsing criteria get complicated, this might work better. But you still might write out the files using generic methods rather than creating new documents and then saving them as plain text.

    Does this help?

  3. #3
    5 Star Lounger
    Join Date
    Apr 2001
    Location
    Arriving Somewhere but not Here
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: split text file into 2 or more files (Word 200

    Thanks, the "importing to a string array" idea probably will help.

    (thinking rather than) stuck

Posting Permissions

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