Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool to merge MS Word files

I have huge number of Word files I need to merge (join) into one file, and will be time consuming to use the Word merger (one by one). Have you experienced any tool that can handle this job?

like image 467
whiz Avatar asked Nov 10 '08 09:11

whiz


People also ask

How do I merge Word documents and keep formatting online?

Create a new Word document you will place the merged documents, and then click Insert > Object > Text from File. See screenshot: 2. In the opening Insert File dialog box, please (1) open the folder containing documents you will merge; (2) select the documents you will merge; and then (3) click the Insert button.

Where is merge tool in Word?

In Microsoft Office Word 2003 and in earlier versions of Word, point to Letters and Mailings on the Tools menu, and then click Mail Merge Wizard. In Microsoft Office Word 2007, click Start Mail Merge in the Start Mail Merge group on the Mailings tab, and then click Step by Step by Mail Merge Wizard.


2 Answers

Sub MergeAllDocuments(AllDocumentsPath as String, MasterDocumentPath as String)
  Dim MasterDocument As Document

  Set MasterDocument = Documents.Open(FileName:=MasterDocumentPath)

  TheDocumentPath = Dir(AllDocumentsPath , vbNormal)
  While TheDocumentPath <> ""
    ' Append the next doc to the end of the master doc. (The 
    ' special "\EndOfDoc" bookmark is always available!)
    MasterDocument.Bookmarks("\EndOfDoc").Range.InsertFile TheDocumentPath
    TheDocumentPath = Dir
  Wend

  MasterDocument.Save
End Sub

MergeAllDocuments "C:\MySeparateDocuments\*.doc", "C:\MasterDocument.doc"

I have one question - why do you want do do such a thing (with a "huge number" of documents, at least)?

like image 128
Tomalak Avatar answered Sep 28 '22 05:09

Tomalak


I came across a post by Graham Skan a while back. It might get you started:

Sub InsertFiles()
    Dim strFileName As String
    Dim rng As Range
    Dim Doc As Document
    Const strPath = "C:\Documents and Settings\Graham Skan\My Documents\Allwork\" 'adjust as necessary '"

    Set Doc = Documents.Add
    strFileName = Dir$(strPath & "\*.doc")
    Do
        Set rng = Doc.Bookmarks("\EndOfDoc").Range
        If rng.End > 0 Then 'section break not necessary before first document.'
            rng.InsertBreak wdSectionBreakNextPage
            rng.Collapse wdCollapseEnd
        End If
        rng.InsertFile strPath & "\" & strFileName
        strFileName = Dir$()
    Loop Until strFileName = ""
End Sub
like image 36
Mitch Wheat Avatar answered Sep 28 '22 06:09

Mitch Wheat