Save Parts of Large Mailmerge as Separate Files

J

John

I have a very large list that that I want to email different parts of to
different departments. I'd like to save each department's letters into
a separate file as part of the merge process. The question
is how can I merge the document and have part of the merge saved to a
new file each time the department name changes? Ideally, I would like
the file name to be based on the department name.

I've done work with macros similar to this before, but it's been years
and I'm a bit rusty. Thanks for any advice.
 
G

Graham Mayor

You appear to have asked this in a number of Word neswgroups at least two of
which have received replies.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

John

The problem is that I'm going to have about 2,000 pages (one per
employee)split over 125+ departments, so I really didn't want to run
each separately - I was really looking to automate the process.
 
D

Doug Robbins

The code in the macro provided below if for an entirely different purpose,
but if you have the datasource ordered by Department, and you create a
catalog type mailmerge with the department mergefield in a single cell table
and execute that merge, then merge the letters to a new file, you could
modify the macro so that it iterates through the catalog merge document to
determine the number of records for each department , then grab that number
of Sections from the formletter merge document and same them to a file with
the name of the department and then repeat that process for each department:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top