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.

Re: How to merge two .doc files? by Peter

Peter
Tue Mar 07 12:01:41 CST 2006

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

hth,

-Peter

"Andrew" <Andrew@discussions.microsoft.com> wrote in message
news:865A0753-BA1E-4939-93B0-3B21513D7C61@microsoft.com...
> 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.
>


Re: How to merge two .doc files? by Charles

Charles
Tue Mar 07 14:04:56 CST 2006

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

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
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.


"Andrew" <Andrew@discussions.microsoft.com> wrote in message
news:865A0753-BA1E-4939-93B0-3B21513D7C61@microsoft.com...
> 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.
>



Re: How to merge two .doc files? by Andrew

Andrew
Tue Mar 07 14:45:03 CST 2006


> 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.