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 / April 2004

Tip: Looking for answers? Try searching our database.

Header-Detail and Tables

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Terry Moriarty - 23 Mar 2004 23:24 GMT
I'm creating a Word Document from a data source that
contains the following 3 fields: category, sequence
number, statement.

The document must contain a table for each category, so
that the output looks like:

Category Name: Administration

Table of sequence number and statements

Category Name: Security

Table of sequence number and statements

I'm using mail merge for document type of directory.  I
can get one big table of all the sequence numbers and
statements, but when I insert the commands for the
Category Name, I get a table with only one row in it for
each row in the data source.  

Any ideas are greatly appreciated.
Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS - 24 Mar 2004 01:30 GMT
Hi Terry,

See Microsoft Knowledge base article KB294686 "HOW TO: Use Mail Merge to
Create a List Sorted by Category in Word 2002"

http://support.microsoft.com/?kbid=294686

Signature

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested.  Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP

> I'm creating a Word Document from a data source that
> contains the following 3 fields: category, sequence
[quoted text clipped - 18 lines]
>
> Any ideas are greatly appreciated.
Terry Moriarty - 24 Mar 2004 20:01 GMT
Thanks.

But this knowledgebase article doesn't discuss how to put
the detail line items into a table.  That's what I'm
trying to do.

Terry Moriarty
>-----Original Message-----
>Hi Terry,
[quoted text clipped - 28 lines]
>
>.
Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS - 26 Mar 2004 08:08 GMT
You will need to use a bit of VBA to achieve that.

First, create a Directory type mailmerge main document with the category,
sequence number and statement mergefields in the cells of a single row three
column table.  Then execute this merge to a new document so that what you
get is a document containing a table with all of the data in it, but with no
heading row.

Then with that table as the active document, run the following macro:

Dim source As Document, target As Document, scat As Range, tcat As Range,
data As Range, stab As Table, ttab As Table
Dim i As Long, j As Long
Set source = ActiveDocument
Set target = Documents.Add
Set stab = source.Tables(1)
Set ttab = target.Tables.Add(Range:=Selection.Range, numrows:=1,
numcolumns:=2)
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.Rows.Add
       Set data = stab.Cell(i, 2).Range
       data.End = data.End - 1
       ttab.Cell(ttab.Rows.Count, 1).Range = data
       Set data = stab.Cell(i, 3).Range
       data.End = data.End - 1
       ttab.Cell(ttab.Rows.Count, 2).Range = data
   Else
       ttab.Rows.Add
       Set data = stab.Cell(i, 2).Range
       data.End = data.End - 1
       ttab.Cell(ttab.Rows.Count, 1).Range = data
       Set data = stab.Cell(i, 3).Range
       data.End = data.End - 1
       ttab.Cell(ttab.Rows.Count, 2).Range = data
   End If
Next i

If the original data is in a Word table, you could just delete the heading
row and then run the above macro when the data document is active.

Signature

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested.  Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP

> Thanks.
>
[quoted text clipped - 44 lines]
>>
>>.
Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS - 26 Mar 2004 10:46 GMT
Here's a slight modification that will handle any number of columns of data:

' Macro to create multiple items per condition 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.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
   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 post any further questions or followup to the newsgroups for the
benefit of others who may be interested.  Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP

> Thanks.
>
[quoted text clipped - 44 lines]
>>
>>.
Terry Moriarty - 09 Apr 2004 17:56 GMT
THanks you.  
I finally got around to testing this and it works fine.

My only question is why the scat.end = scat.end -1
statements are needed (there are also .end statements for
tcat and data).

Thanks again,
 Terry Moriarty
>-----Original Message-----
>Here's a slight modification that will handle any number of columns of data:
[quoted text clipped - 89 lines]
>
>.
Doug Robbins - Word MVP - 10 Apr 2004 09:18 GMT
When you use

Set scat = stab.Cell(i, 1).Range

you are setting a range to the whole of the cell, rather that just to the
text in the cell.

scat.End = scat.End - 1

shortens the range so that it contains just the text in the cell.

If you do not shorten the range in this way, when you use

ttab.Cell(1, 1).Range = scat

you will get a single cell table inserted inside the ttab table, rather than
just the text.

Likewise of course for the other tcat and data ranges.

Signature

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested.  Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP

> THanks you.
> I finally got around to testing this and it works fine.
[quoted text clipped - 118 lines]
>>
>>.
Terry Moriarty - 10 Apr 2004 22:09 GMT
Thanks again.  This makes sense to me.

You've helped a lot in getting my Word document formatted
correctly.

Using your code to start with, I know have a VBA module
that puts the Category as a level 2 heading and a separate
table for each Category.

This has been a real education for me.

Thanks so much.

Terry Moriarty
>-----Original Message-----
>When you use
[quoted text clipped - 141 lines]
>
>.
 
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.