Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    May 2003
    Location
    Pennsylvania, USA
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Concatenating Files

    I have a directory with about 400 small MS Word files that I would like to concatenate into a single file. How can I do this without having to open each file in Word and manually append it to the document? I tried going to DOS and using the copy command with wild characters (*.doc) but only one file got copied to the output.

    Thanks for the help.

    Don.

  2. #2
    ileacy
    Guest

    Re: Concatenating Files

    The syntax for the copy command is:

    Copy file1+file2+... newfile

    The + is required for concatenation.

    You can use wildcards in a batch FOR loop but you probably don't want to. The concatenated files would probably not be a valid WORD document. To properly handle this problem you need to use a WORD VBA macro.

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Concatenating Files

    You should probably ask this question in the Word forum. You can not just concatenate the files since Word would not recognize the format of the resulting file. You will need a Word VBA macro to do this and end up with a file that Word can use.
    Legare Coleman

  4. #4
    Star Lounger
    Join Date
    May 2003
    Location
    Pennsylvania, USA
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Concatenating Files

    Actually, I found out by looking at some Newsgroup postings that you need to convert the files to text, and then you can easily concatenate them by using a utility called concat/split. (See http://www.jddesign.freeserve.co.uk/concat-s.htm)

    Don

  5. #5
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Concatenating Files

    But by converting them to text files, aren't you having to open them in Word anyway?
    I would have thought a macro to open and insert each file into a single document would be the fastest solution.

  6. #6
    Star Lounger
    Join Date
    May 2003
    Location
    Pennsylvania, USA
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Concatenating Files

    No, you don't have to open the documents. Word2000 has a batch conversion wizard. Click on file/new/other documents/batch conversion. It lets you select files and convert them into a variety of other formats, one of which it text. Works great.

  7. #7
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Concatenating Files

    I use the following "no-frills" macro. It makes a new document, and puts all files (*.DOC, *.RTF, *.HTML, *.TXT ...) in the folder (Path1) into it in alphabetical order.
    Most of the code was stolen from the Word2000 online help (but any bugs are still mine <img src=/S/wink.gif border=0 alt=wink width=15 height=15>).

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Regards, Klaus


    <pre>Sub Accumulator()
    '
    Path1 = "c:myfolder" ' Set Path.
    Documents.Add DocumentType:=wdNewBlankDocument
    ChangeFileOpenDirectory Path1

    With Application.FileSearch
    .NewSearch
    .LookIn = Path1
    .SearchSubFolders = False
    .FileName = "*"
    .FileType = msoFileTypeAllFiles
    .Execute SortBy:=msoSortByFileName, _
    SortOrder:=msoSortOrderAscending

    For i = 1 To .FoundFiles.Count
    Selection.TypeText .FoundFiles(i)
    Selection.TypeParagraph
    Selection.InsertFile FileName:=.FoundFiles(i), _
    ConfirmConversions:=False
    Selection.InsertBreak Type:=wdPageBreak
    Next i
    End With
    End Sub
    </pre>


Posting Permissions

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