Log in

View Full Version : Interleaving two word documents



zfeld75
05-11-2013, 08:29 PM
I know there was similar question posted and marked as solved even though it wasn't solved.
My question is a little different.
I need to merge two word documents but not just by appending them.
If I have test1.docx and test2.docx I need to interleave after paragraph 1 from test1 I need to add paragraph 1 from test2, then after paragraph 2 (which is now paragraph 3)in test1 I need to add paragraph 2 from test2, and so on.

I don't know where to start

macropod
05-11-2013, 11:39 PM
You could use a macro like the following:
Sub Interleave()
Application.ScreenUpdating = False
Dim i As Long, TgtDoc As Document, SrcDoc As Document, Rng As Range
Set SrcDoc = Documents.Open(FileName:="Path & name for the 'source' document", AddToRecentFiles:=False)
Set TgtDoc = Documents.Open(FileName:="Path & name for the 'target' document", AddToRecentFiles:=False)
With TgtDoc
For i = .Paragraphs.Count To 1 Step -1
Set Rng = .Paragraphs(i).Range
Rng.Collapse wdCollapseStart
SrcDoc.Paragraphs(i).Range.Copy
Rng.Paste
Next
End With
Application.ScreenUpdating = True
End Sub
Note: As coded, the macro is intended to run from a different document to either of the documents involved in the interleaving. There is also no error-checking, so don't be surprised if the code fails when the source document has fewer paragraphs than the target document or that the latter paragraphs from a source document having more paragraphs than the target document aren't copied.