Re: Conditional page eject in "Catalogue" mail merge
- From: "Doug Robbins - Word MVP" <dkr@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 15 May 2007 11:16:15 +0200
The following macro will separate a catalog type mailmerge into separate
tables when the data in the first field changes.
' 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
--
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
"Lüko Willms" <l.willms@xxxxxxxxxxxxxx> wrote in message
news:czd2LKcn8EGd-pn2-Wsk8CwEr8iQ9@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have a mailmerge of type "catalogue" and want to insert a page
eject when a certain field changes. How do I do that?
Let's say, this controlling field is called "Zimmer_Nr", as German
for Room_No.
I haven't done Winword programming for at least half a year and
can't remember how to do it, but I would need it for tomorrow...
MS-Office 2000, data source is an Excel ***.
I was thinking to insert a mailmerge IF ... ELSE before the first
item in the data row, comparing the actual value of the mailmerge
field "Zimmer_Nr" to a DOCVARIABLE, and assign the current value of
the "Zimmer_Nr" to a DOCVARIABLE at the end of the data row.
Or can I access the field value indexed by the MERGESEQ value?
Yours,
L.W.
.
- References:
- Conditional page eject in "Catalogue" mail merge
- From: Lüko Willms
- Conditional page eject in "Catalogue" mail merge
- Prev by Date: Re: Too Many Data Fields in Mail Merge
- Next by Date: Re: mail merge -- attachment at bottom of email
- Previous by thread: Re: Conditional page eject in "Catalogue" mail merge
- Next by thread: Re: Dialog Box Alert upon opening a mail merge main document
- Index(es):