Insert multiple files into a template

M

Mei Qin

Hello,

I have the following code to insert files into a pre-
designed word template:

Dim objWord As Word.Document
Set objWord = GetObject
("C:\Reports\template1.doc", "Word.Document")
objWord.Content.InsertFile "c:\reports\Report1.rtf"

It works fine. But when I tried to insertFile again, the
second will replace the first file I inserted. How do I
insert multiple files one after another into a word
template?

Thanks for any help!

Mei
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Mei Qin > écrivait :
In this message said:
Hello,

I have the following code to insert files into a pre-
designed word template:

"template1.doc" is a document, not a temaplte. tempalte have the ".dot"
extension.
Dim objWord As Word.Document
Set objWord = GetObject
("C:\Reports\template1.doc", "Word.Document")
objWord.Content.InsertFile "c:\reports\Report1.rtf"

It works fine. But when I tried to insertFile again, the
second will replace the first file I inserted. How do I
insert multiple files one after another into a word
template?

Your code:

objWord.Content.InsertFile "c:\reports\Report1.rtf"

Here, you are saying "Take the content of objWord and replace it with
Report1.rtf"
When you insert the next file, Report1.rtf is part of the Content of objWord
and gets replaced by whatever file you are inserting next.

Here is an example *directly* from the online VBA help: It is based on the
Selection object, but you can easily adapt it to your objWord.Range object.

'_______________________________________
Documents.Add
ChDir "C:\TMP"
myName = Dir("*.TXT")
While myName <> ""
With Selection
.InsertFile FileName:=myName, ConfirmConversions:=False
.InsertParagraphAfter
.InsertBreak Type:=wdSectionBreakNextPage
.Collapse Direction:=wdCollapseEnd
End With
myName = Dir()
Wend
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

Mei Qin

I am pretty new to this. Would you please post the code
for objWord.Range? Because I use the selection to
insertfiles, it gives me the blank page.

Thanks!

Mei
 

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