Reply
 
Thread Tools Display Modes
  #1   Report Post  
Shannon W via OfficeKB.com
 
Posts: n/a
Default Saving final document to multiple files when merge document has multiple section

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.
  #2   Report Post  
Doug Robbins
 
Posts: n/a
Default

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

--
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
"Shannon W via OfficeKB.com" wrote in message
...
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.



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
opening and changing a document by multiple people at the same tim GSelser Microsoft Word Help 0 August 11th 05 10:05 PM
How do I open multiple Word 2003 files to display on dual monitors mally Microsoft Word Help 6 July 4th 05 11:00 AM
Saving multiple files at once to same location dwight Microsoft Word Help 1 April 27th 05 10:48 PM
How can you merge data from multiple source files? Charles Miller Mailmerge 1 April 12th 05 02:05 PM
Mail Merge Final Step in Word 2003 XP blnorwood Mailmerge 2 January 14th 05 07:02 AM


All times are GMT +1. The time now is 10:05 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"