Insert a document into another document?

A

aualias

I am using a template to create documents.
I would like to create one large document using documents created with the
template. However, there is no need to save any of the intermediate
documents.

Pseudocode would be something like this...
Create an empty Word document = docMain.
While there is data
{
Create a Word document from the template.
Modify fields in the document.
Append the newly created doc to docMain.
}
Save docMain

If I save each document created from the template to disk I should be able
to insert with the Selection.InsertFile() method. However, it would be
better if I could insert the document without having to save it to disk.

Is this possible? How would I do it?

TIA

David
 
H

Helmut Weber

Hi,

like this:

Sub test552413()
Dim docMain As Document
Dim docTemp As Document
Set docMain = Documents("testlong.doc")
Set docTemp = Documents("testshort.doc")
docMain.Range.InsertAfter docTemp.Range
End Sub

If you want to preserve formatting,
you may have to use copy and paste, like:

Dim docMain As Document
Dim docTemp As Document
Dim rtmp As Range
Set docMain = Documents("testlong.doc")
Set docTemp = Documents("testshort.doc")
Set rtmp = docMain.Range
rtmp.Collapse Direction:=wdCollapseEnd
docTemp.Range.Copy
rtmp.Paste

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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