none
Combine two word documents RRS feed

  • Question

  • Hi All

    Are there any possibilities to combine two word documents into one word document.

    Word document 1 consists of 100 pages. it's text area on the top of the each page.

    Word document 2 consist of 100 pages. it's text area on the bottom of the each page.

    I want to combine these two documents into one. i.e. Document 1 1st page and Document 2 1st page in one page then Document 1 2nd page and Document 2 2nd page in one page  and soon.

    Please any one advice me how to do that

    Thank You

    Sunday, December 25, 2011 2:33 PM

Answers

  • Create a new document.

    Press Alt+F11 to activate the Visual Basic Editor.

    Select Insert | Module.

    Copy the following macro into the module:

    Sub CombineDocs()
        Dim doc1 As Document, doc2 As Document, doc3 As Document
        Dim i As Long
        Dim rngS As Range
        Dim rngT As Range
        Application.ScreenUpdating = False
        Set doc1 = Documents("Doc1.docx")
        Set doc2 = Documents("Doc2.docx")
        Set doc3 = Documents.Add
        For i = 1 To doc1.Sections.Count
            Set rngS = doc1.Sections(i).Range
            rngS.MoveEnd Unit:=wdCharacter, Count:=-1
            rngS.Copy
            Set rngT = doc3.Content
            rngT.Collapse Direction:=wdCollapseEnd
            rngT.Paste
            Set rngS = doc2.Sections(i).Range
            rngS.Copy
            Set rngT = doc3.Content
            rngT.InsertParagraphAfter
            rngT.Collapse Direction:=wdCollapseEnd
            rngT.Paste
        Next i
        Application.ScreenUpdating = True
    End Sub
    

    Substitute the correct names for the documents.

    Open both documents.

    Run the macro.


    Regards, Hans Vogelaar
    • Marked as answer by dukdpk Monday, December 26, 2011 5:24 AM
    Sunday, December 25, 2011 6:01 PM

All replies

  • Word document 2 consist of 100 pages. it's text area on the bottom of the each page.


    How has that been done? By setting the vertical alignment to Bottom in the Layout tab of the Page Setup dialog? Or by increasing the Space Before of the first paragraph of each page? Or by hitting the Enter key repeatedly to move the text down?
    Regards, Hans Vogelaar
    Sunday, December 25, 2011 2:37 PM
  • Hi Hans

    Actually I created two documents using mail merge. Now I want to take these two document into one.

     

    Thank You

     

    Sunday, December 25, 2011 3:36 PM
  • OK, but can you answer my question, please?


    Regards, Hans Vogelaar
    Sunday, December 25, 2011 3:40 PM
  • Hi Hans

     

    hitting the Enter key repeatedly to move the text down

     

    Thank You

    Sunday, December 25, 2011 4:49 PM
  • That actually makes it more difficult to combine the documents. Would it be possible to generate the document again without the empty paragraphs at the top of the pages?
    Regards, Hans Vogelaar
    Sunday, December 25, 2011 5:01 PM
  • hi Hans

    Yes I can generate Document 2 again without the empty paragraphs at the top of the pages. Somehow I want to Combine these two documents into one document. My expected document should be somthing like as following

    Both Document1 page no 1 and Document 2 page no 1 should be in Expected document page no 1. (first display Document 1 page no 1 contains then Document 2 page no 1 contains )

    Both Document1 page no 2 and Document 2 page no 2 should be in Expected document page no 2. (first display Document 1 page no 2 contains then Document 2 page no 2 contains )

    so on up to 100 pages

     

    Thank You

     

    Sunday, December 25, 2011 5:33 PM
  • Create a new document.

    Press Alt+F11 to activate the Visual Basic Editor.

    Select Insert | Module.

    Copy the following macro into the module:

    Sub CombineDocs()
        Dim doc1 As Document, doc2 As Document, doc3 As Document
        Dim i As Long
        Dim rngS As Range
        Dim rngT As Range
        Application.ScreenUpdating = False
        Set doc1 = Documents("Doc1.docx")
        Set doc2 = Documents("Doc2.docx")
        Set doc3 = Documents.Add
        For i = 1 To doc1.Sections.Count
            Set rngS = doc1.Sections(i).Range
            rngS.MoveEnd Unit:=wdCharacter, Count:=-1
            rngS.Copy
            Set rngT = doc3.Content
            rngT.Collapse Direction:=wdCollapseEnd
            rngT.Paste
            Set rngS = doc2.Sections(i).Range
            rngS.Copy
            Set rngT = doc3.Content
            rngT.InsertParagraphAfter
            rngT.Collapse Direction:=wdCollapseEnd
            rngT.Paste
        Next i
        Application.ScreenUpdating = True
    End Sub
    

    Substitute the correct names for the documents.

    Open both documents.

    Run the macro.


    Regards, Hans Vogelaar
    • Marked as answer by dukdpk Monday, December 26, 2011 5:24 AM
    Sunday, December 25, 2011 6:01 PM
  • Hi Hans

    I tried your macro. It combinse after the one document. I want to combine both first pages into one then second pages after that like so on

     

    Thanks 

     

     

    Sunday, December 25, 2011 6:23 PM
  • You mentioned that the two documents were the result of a mail merge. If so, the documents should contain a section for each record in the data source. The macro assumes that the documents are structured that way.
    Regards, Hans Vogelaar
    Sunday, December 25, 2011 6:38 PM
  • Hi Hans

    Thank you for your reply. Your macro is working. Once again thank you

     

     

    Monday, December 26, 2011 5:24 AM
  • Hi Hans

    Can I give location to paste second word document in final document. i.e want to paste second document just after the first document.now there is a space(similar to paragraph space) between first word document contain and second word document contain. Can I reduce this space into 1 line. I remove the following statement but not successful.

    rngT.InsertParagraphAfter

     

    Thank You

    Dinusha

     

    Tuesday, December 27, 2011 3:17 AM
  • Does the first document contain one or more empty paragraphs at the end of each page, or does the second document contain one or more empty paragraphs at the beginning of each page?
    Regards, Hans Vogelaar
    Tuesday, December 27, 2011 10:41 AM
  • Hi Hans

    Both documents contain more emply paragraphs.  first document contain more empty paragraphs at the end of each page as well as second document more empty paragraphs at the beginning of each page.

     

    Thank You

    Tuesday, December 27, 2011 3:11 PM
  • You should remove those empty paragraphs before performing the mail merge to create the two documents.
    Regards, Hans Vogelaar
    Tuesday, December 27, 2011 3:23 PM
  • Hi Hans

     

    What does mean of remove those empty paragraph before performing the mail merge to create the two documents?

     I did first mail merge document in A4 Landscapde. It contains  a table and table's height is nearly 6cm.

    second mail merge document also in A4 lanscape. It also contains a table and table's height is about 10am. 

    I ment empty paragraph are, those empty space in after(First Document) and before (Second Document) the table area. Please could you expain how to remove these empty area.

     

    Thank You

    Tuesday, December 27, 2011 4:12 PM
  • On the Home tab of the ribbon, in the Paragraph group, turn on (highlight) the Show/Hide ¶ button.

    Empty paragraphs will show as lines containing only ¶. If you see several consecutive empty paragraphs, delete all except one. (You can never delete the last paragraph marker ¶ in a document)


    Regards, Hans Vogelaar
    Tuesday, December 27, 2011 4:26 PM
  • Hi Hans

     

    Thank you for your reply. Yes now I can get combine document.

     

    Thanks 

    Tuesday, December 27, 2011 5:04 PM