A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

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



 
 
Thread Tools Display Modes
  #1  
Old September 16th, 2005, 06:22 PM
Shannon W via OfficeKB.com
external usenet poster
 
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  
Old September 19th, 2005, 05:31 AM
Doug Robbins
external usenet poster
 
Posts: n/a
Default Saving final document to multiple files when merge document has multiple section

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.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple merge with IncludeText generating extraneous hidden c Judy Mailmerge 2 May 5th, 2005 03:51 PM
Keeping tracked changes when copying multiple files to a single document Derek Gadd General Discussion 2 September 29th, 2004 11:50 PM
How to run word and pass a mail merge values and fax it to the recipient Belinda Mailmerge 2 June 13th, 2004 12:49 AM
Word hangs saving new document after merge to access database Sandy Mailmerge 4 May 19th, 2004 03:43 PM
Saving separated mail merge files, with data in datasource as name !!!!!!! Van123 Mailmerge 2 May 7th, 2004 11:51 PM


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


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.