Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Sep 2001
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Combining 100 documents into 1 (Word 2000 SP-3)

    Suppose I have a hundred of (similarly formatted) documents consecutively named 001.doc, 002.doc ...

    What's the easiest way to combine them - in the named order - into one big document?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Combining 100 documents into 1 (Word 2000 SP-3)

    The following macro should do more or less what you want. Don't forget to modify the path and number of documents.

    Sub ConcatenateDocuments()
    ' Adapt as needed
    Const strPath = "D:Word"
    Const intMax = 100

    Dim i As Integer
    Dim docNo1 As Document
    Dim docNoi As Document
    Dim rng As Range

    On Error GoTo ErrHandler

    Application.ScreenUpdating = False

    Set docNo1 = Documents.Open(FileName:=strPath & "001.doc", AddToRecentFiles:=False)
    Set rng = docNo1.Content
    rng.Collapse Direction:=wdCollapseEnd
    rng.InsertAfter vbCrLf

    For i = 2 To intMax
    Set docNoi = Documents.Open(FileName:=strPath & Format(i, "000") & ".doc", AddToRecentFiles:=False)
    docNoi.Content.Copy
    Set rng = docNo1.Content
    rng.Collapse Direction:=wdCollapseEnd
    rng.InsertAfter vbCrLf
    rng.Collapse Direction:=wdCollapseEnd
    rng.Paste
    docNoi.Close SaveChanges:=wdDoNotSaveChanges
    Next i

    MsgBox "Don't forget to save this document under another name.", vbInformation

    ExitHandler:
    Application.ScreenUpdating = True
    Exit Sub

    ErrHandler:
    MsgBox "Something went wrong: " & Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

  3. #3
    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: Combining 100 documents into 1 (Word 2000 SP-3)

    A variation on Hans' method would be to use InsertFile to insert each file after the first. I'm not sure which would give you the best results; perhaps they would come out the same.

    One potential issue to bear in mind is the possibility that with large files you might have to save intermittently (e.g., after every fifth file). Maybe I've only had this problem with multple find/replace operations, but I suspect that any large scale changes might fill up Word's buffers (e.g., Undo buffer) and generate an error at some point.

Posting Permissions

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