Combining Documents in Code

D

Damien

All,

I've written this code to combine two documents in code, but I don't really
like it.

I did try using the Range object, but as the letters have Word tables in, it
didn't seem to work. I need to capture all tables and formatting in the
document.

Does anyone have any better ideas or code?

Thanks


Damien



Private Function CombineDocuments(letter_object As Word.Document,
projection_object As Word.Document) As Word.Document

Dim Doc As Word.Document

Set Doc = Documents.Add(DocumentType:=wdNewBlankDocument)

'Copy letter
Windows(letter_object.Name & " (Read-Only)").Activate

With Selection
.WholeStory
.Copy
End With

'Paste in new document
Doc.Activate

With Doc.Range
.PasteAndFormat (wdPasteDefault)
Selection.EndKey Unit:=wdStory
End With

'Copy projection_object
Windows(projection_object.Name & " (Read-Only)").Activate

With Selection
.WholeStory
.Copy
End With

'Paste in new document
Doc.Activate

With Selection
.InsertBreak Type:=wdPageBreak
.PasteAndFormat (wdPasteDefault)
End With

Set CombineDocuments = Doc

End Function
 
A

Alex Ivanov

Try this:

Dim wd As Word.Application
Dim dest As Document
Set wd = Application
Set dest = wd.Documents.Add
dest.Windows(1).View = wdOutlineView
dest.Range.Subdocuments.AddFromFile ("C:\Doc1.doc")
dest.Range.Subdocuments.AddFromFile ("C:\Doc2.doc")
dest.Characters.First.Delete
dest.Windows(1).View = wdPrintView
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top