Automating Word Mail Merge and splitting final document

S

S Willison

I am automating Word to create a mail merge document in C#. I need to save
the final, merged document to a SQL Server database for historical purposes.
When there is just one record in the merge, this is easy. However, when I am
merging multiple records I need to capture each record's portion of the final
merge document and save only that part to the database for that record. I
notice that the final document has a section break between each record. Is
it possible to use that or some other means to split the document behind the
scenes? I only want to display the one, single document to the user rather
than looping through the records and popping up a copy of Word for each
record. Any ideas? Thanks very much for any insight.
 
C

Cindy Meister

Well, there are a couple of possible approaches for pulling mail merges
apart. One is outlined in the mail merge FAQ on my website
(http://homepage.swissonline.ch/cindymeister), another by Doug Robbins at
word.mvps.org.

Given how you want to display them to the user, I'm inclined to say use
Doug's approach, that pulls it apart section by section. I'd use the
Range.FormattedText property to pull the content of each section into the
window you're showing to the user.

Word doesn't have anything built into it that will let you display a section
instead of the entire document.

-- Cindy
 
S

S Willison

Cindy,

Thanks for the help. I was able to loop through the sections collection of
the ActiveDocument and get access to each item's merged record via
Range.FormattedText.Text. Thanks again, I really appreciate the help!

Shannon
 

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