Re: page break on merge field content change
From: Doug Robbins (dkr_at_NOmvpsSPAM.org)
Date: 09/15/04
- Next message: Bobsgirl: "Re: Trouble formatting Excel data to be recognized when merged int"
- Previous message: Alex_at_islands.vi: "I HAVE NO MAIL MERGE UNDER TOOLS MENU. I AM TRYING TO MALE MAIL.."
- In reply to: sharon: "page break on merge field content change"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 14 Sep 2004 21:21:58 -0400
I assume that you are creating some sort of directory. If that's correct,
set up the merge fields in the cells of a one row table and execute the
merge to a new document, then (possibly after a bit of tweaking to get it to
act on the correct column, as it is set up to act on the first column), run
the following macro:
' Macro to create multiple items per condition in separate tables from a
directory type mailmerge
Dim source As Document, target As Document, scat As Range, tcat As Range
Dim data As Range, stab As Table, ttab As Table
Dim i As Long, j As Long, k As Long, n As Long
Set source = ActiveDocument
Set target = Documents.Add
Set stab = source.Tables(1)
k = stab.Columns.Count
Set ttab = target.Tables.Add(Range:=Selection.Range, numrows:=1,
numcolumns:=k - 1)
Set scat = stab.Cell(1, 1).Range
scat.End = scat.End - 1
ttab.Cell(1, 1).Range = scat
j = ttab.Rows.Count
For i = 1 To stab.Rows.Count
Set tcat = ttab.Cell(j, 1).Range
tcat.End = tcat.End - 1
Set scat = stab.Cell(i, 1).Range
scat.End = scat.End - 1
If scat <> tcat Then
ttab.Rows.Add
j = ttab.Rows.Count
ttab.Cell(j, 1).Range = scat
ttab.Cell(j, 1).Range.Paragraphs(1).PageBreakBefore = True
ttab.Rows.Add
ttab.Cell(j + 1, 1).Range.Paragraphs(1).PageBreakBefore = False
For n = 2 To k
Set data = stab.Cell(i, n).Range
data.End = data.End - 1
ttab.Cell(ttab.Rows.Count, n - 1).Range = data
Next n
Else
ttab.Rows.Add
For n = 2 To k
Set data = stab.Cell(i, n).Range
data.End = data.End - 1
ttab.Cell(ttab.Rows.Count, n - 1).Range = data
Next n
End If
Next i
-- Please respond to the Newsgroup for the benefit of others who may be interested. Questions sent directly to me will only be answered on a paid consulting basis. Hope this helps, Doug Robbins - Word MVP "sharon" <anonymous@discussions.microsoft.com> wrote in message news:015c01c49a88$d0f678e0$a401280a@phx.gbl... > When using mergefields, how do you insert an intelligent > page break? Data is already sorted (grouped), now we > need page breaks placed for each "group" of data. > > Ex. Select name, address, city, state > sort by state, city > page break on city > > This would mean that, each time a new city name is > encountered, a page break is inserted. > > Thanks in advance for the feedback.
- Next message: Bobsgirl: "Re: Trouble formatting Excel data to be recognized when merged int"
- Previous message: Alex_at_islands.vi: "I HAVE NO MAIL MERGE UNDER TOOLS MENU. I AM TRYING TO MALE MAIL.."
- In reply to: sharon: "page break on merge field content change"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|