Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / January 2005

Tip: Looking for answers? Try searching our database.

Word.mailmerge.tableformat.groupbyfield

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
laschmitz - 20 Jan 2005 22:47 GMT
Is it possible to create a table using a merge and group by company name as a
column header (5 columns 2 rows to the table) and list individuals of that
company in the cell below the column header then advance to the next column
for a new company name?  

Company 1 name     Company 2 Name    Company 3 Name
person one         person one        person one
person two         person two        person two
Doug Robbins - 20 Jan 2005 23:30 GMT
If you create a catalog (or in Word XP and later, a directory) type
mailmerge, you could probably run a modified version of the following macro
over the document created by executing that mailmerge to achieve what you
are after.

' 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

Signature

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

> Is it possible to create a table using a merge and group by company name
> as a
[quoted text clipped - 6 lines]
> person one         person one        person one
> person two         person two        person two
Lynn - 21 Jan 2005 16:15 GMT
Thank you Doug, however the person that I need to do this for is still using
Office 2000 so I don't think I can create this for her.  Or, can I create it
in XP and the file be compatible?

> If you create a catalog (or in Word XP and later, a directory) type
> mailmerge, you could probably run a modified version of the following macro
[quoted text clipped - 54 lines]
> > person one         person one        person one
> > person two         person two        person two
Doug Robbins - 22 Jan 2005 00:49 GMT
This should work in Word 2000 as well.  The only reason for the reference to
Word XP was because what was termed a "catalog" mailmerge in Word 2000 and
earlier versions is referred to as a "directory" mailmerge in Word XP and
later.

Signature

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

> Thank you Doug, however the person that I need to do this for is still
> using
[quoted text clipped - 63 lines]
>> > person one         person one        person one
>> > person two         person two        person two
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.