Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2006

Tip: Looking for answers? Try searching our database.

How to merge two .doc files?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew - 07 Mar 2006 17:51 GMT
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.
Peter - 07 Mar 2006 18:01 GMT
replace
msdoc.Merge "c:\CQInfo.doc"
with
msdoc.Range.InsertFile "c:\CQInfo.doc"

hth,

-Peter

> Hi, friends,
>
[quoted text clipped - 16 lines]
>
> Could anyone help? Any sample source code? Thanks a lot.
Andrew - 07 Mar 2006 20:45 GMT
> 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.
Charles Kenyon - 07 Mar 2006 20:04 GMT
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.
Signature

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.

> Hi, friends,
>
[quoted text clipped - 18 lines]
>
> Could anyone help? Any sample source code? Thanks a lot.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.