Re: page break on merge field content change

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Doug Robbins (dkr_at_NOmvpsSPAM.org)
Date: 09/15/04


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. 


Relevant Pages

  • Re: [OT] Places for a programmer to live?
    ... I think it might be going down a *little* soon, but yikes, it's high. ... contracting is the name of the game, and while you probably won't be using Agile methodologies to build the Next Big Thing, you'll at least have a fairly well-paying and steady job. ... because of some sort of wind thing. ... You're not going to find that 'cept for probably way in the city, or way out. ...
    (comp.lang.ruby)
  • Re: Planning a trip to Paris!
    ... You don't need to worry about transportation because the city s well serviced by the Metro. ... I would suggest avoiding the main tourist areas because they can be quite expensive and not all that good. ... You can look at the posted menu and check out the sort of food on people's plates and then select one that looks to be to your liking. ... I found Mercure hotels in France to be quite acceptable, and their cheaper Ibis hotels offer more basic accommodation. ...
    (rec.travel.europe)
  • Re: ok, its confirmed - Bangalore is building a Test team
    ... a sort of desultory thing. ... But an active interest where you root for your team, ... As Modi said the other day "My City, My Team" - that should be the ... If they really cared for Bombay, ...
    (rec.sport.cricket)
  • Re: Revising a first novel ten years later
    ... it'd be prairie and I'd probably need some sort of special ... waiver from the city. ... Describing the road and the riverbank and the caravan approaching the city ...
    (rec.arts.sf.composition)