Help please merging 2 MS Word documents

A

Andrew Mercer

Hi,

I am needing to merge 2 MS Word documents by either merging 2 documents into
one new document or adding one document to the Bottom of the 2nd document.

However whatever I try does not work as I would hope.

1. Document 1 is made up of 2 separate sections.
2. Each section has different Headers and Footers
(that is the reason for the sections)
3. The first section also holds the front page which itself
does not have any headers or footers.
4. Document 2 also has different headers and footers to
any of those in DOcument 1
5. Both documents are built using tables etc and Document 2
is only 1 page in total and the text is, for formatting
reasons, inserted into a table the size of the page.

When I attempt to use InterOp WORD.Selection InsertFile I have the
following issues:

1. Page 1 of document 1 is overwritten with the Header and Footer
for section 1 of document 1. Despite all the Page/Section breaks
being added in an attempt to prevent this.

2. The data (headers, footers, text etc...) of Document 1 cannot be
inserted before the data of Document 2. The error message says the
file cannot be inserted into a table.

3. I tried therefore to add the documents to a new file (ie: instead of
inserting document 1 into document 2) with the same problem.

4. I then tried adding a page break between document 1 and 2 but though
the 2 files inserted there is formatting issues (headers/footers and
extra unwanted pages)

I finally tried the InterOp Word copy/select and paste functionality
to create a blank document and paste the data for document 1 to this new
document.

This worked well.

I then tried:

1. Create blank documentX.
2. Copy and paste data from document 1 into documentX.
3. Copy and paste data from document 2 into documentX.

However the data for document 2 never appears in documentX.

What am I doing wrong:

Code does the following.

1. Create WORD.Application object oWord1
2. Open document 1 in oDocument1 object
3. Activate() document 1
4. Global select of data in document 1
5. Copy data to WORD object oWord1
6. Open blank destination documentX
7. Activate() documentX
8. Paste data from first selection to documentX
9. Open document 2 in oDocument2 object
10. Activate() document 2
11. Global select of data in document 2
12. Copy data to WORD object oWord1
13. Paste data from first selection to documentX
14. Close all Word and document objects
15. Garbage collect

Thanks for any help.

Andrew
 
C

Cindy M.

Hi =?Utf-8?B?QW5kcmV3IE1lcmNlcg==?=,
I am needing to merge 2 MS Word documents by either merging 2 documents into
one new document or adding one document to the Bottom of the 2nd document.
The exact steps depend very much on what needs to be done with the resulting,
merged document. How will it be used?

Given your requirements (retaining headers, footers, sections), I'm inclined to
suggest using the Master Document / Sub-document feature to bring them
together. But the details of what happens depend very much on the question
above...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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