
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.
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]
>
>.