How to merge two .doc files?

A

Andrew

Hi, friends,

I need to merge 2 .doc files: One contains template Header and Footer only,
and the other contains required info.

I did the follows:

Dim mswd As New Word.Application
Dim msdoc As Word.Document

Set msdoc = mswd.Documents.Open("c:\templateHF.doc")
msdoc.Merge "c:\CQInfo.doc"

msdoc.Close
mswd.Quit

However, I got an error: Run-time error 4198 on msdoc.Merge "c:\CQInfo.doc"
line.

Could anyone help? Any sample source code? Thanks a lot.
 
P

Peter

replace
msdoc.Merge "c:\CQInfo.doc"
with
msdoc.Range.InsertFile "c:\CQInfo.doc"

hth,

-Peter
 
C

Charles Kenyon

Try saving your H/F template as a template.

Create a new document based on it. Documents.Add

Insert the other document. Merge is intended for comparing documents and
should give you markup showing differences.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
A

Andrew

replace
msdoc.Merge "c:\CQInfo.doc"
with
msdoc.Range.InsertFile "c:\CQInfo.doc"


Thank you. it worked.

But, now I got another error at line msdoc.Close (see code below)

Run-time error -2147417851(80010105)

Dim mswd As New Word.Application
Dim msdoc As Word.Document

Set msdoc = mswd.Documents.Open("c:\templateHF.doc")
msdoc.Range.InsertFile "c:\CQInfo.doc"

msdoc.Close
mswd.Quit

As a result, could not ope file TemplateHF.doc anymore. It said this file is
locked for editing.

Any ideas? Thanks.
 

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