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 / Mailmerge and Fax / September 2005

Tip: Looking for answers? Try searching our database.

Saving final document to multiple files when merge document has multiple section

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shannon W - 16 Sep 2005 18:21 GMT
I am following a technique found in another thread on this site to loop
through the sections in a final merge document to break the document into
multiple pieces that relate to a specific customer.  The code snippet is
below:

for (int i = 1; i < wordDoc.Sections.Count; i++)
{
                   
     DataRow rowHistory = this.mAppDataSet.History.Rows[(i-1)];

     if(rowHistory != null)                       
           rowHistory["Notes"] = wordDoc.Sections.Item(i).Range.
FormattedText.Text;

}

This works great for documents that do not have any sections defined by the
user - for example, a page break.  Is there any way to distinguish between a
regular page break and the end of the section for a particular merge record's
section?  Thanks in advance.
Doug Robbins - 19 Sep 2005 05:31 GMT
Dim i As Long, Source As Document, Target As Document, Letter As Range
Set Source = ActiveDocument
For i = 1 To Source.Sections.Count Step 2
   Set Letter = Source.Sections(i).Range
   Letter.End = Source.Sections(i + 1).Range.End
   Set Target = Documents.Add
   Target.Range.FormattedText = Letter.FormattedText
   Target.SaveAs FileName:="Letter" & i
   Target.Close
Next i

If each letter contains n sections, replace Step 2 with Step n and
Sections(i + 1) with Sections(i + (n - 1))

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I am following a technique found in another thread on this site to loop
> through the sections in a final merge document to break the document into
[quoted text clipped - 19 lines]
> record's
> section?  Thanks in advance.

Rate this thread:






 
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.