Re: Insert excel data into word via mail merge

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Doug Robbins - Word MVP (dkr_at_NOmvpsSPAM.org)
Date: 12/22/04


Date: Thu, 23 Dec 2004 08:53:20 +1000

Mail merge in Word cannot really hand a multiple items (transactions in your
case) per condition (Employee in your case) situation.

If you have Microsoft Access, I would recommend transferring the data into
Access and then use an Access Report.

Otherwise, you could try further developing the following macro. It would
take some work, but it would be quite feasible to get it to do what you
want.

' 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

-- 
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
"Jane" <Jane@discussions.microsoft.com> wrote in message
news:2AC7515A-107C-42BF-BB73-254C472B1D8A@microsoft.com...
> I want to print year end summaries to the employees who have stock sale
tax
> reported on their W2.  The word doc. that will be sent out contains
standard
> data that these emp. will receive.  However the numbers are in excel.  How
do
> I merge this information into the doc. file in a way so that I don't have
to
> do it manually for 200 emp.
> For eg:
> Joe Smith
> The attached file contains records of the income that has been reported on
> your W2 pursuant to your sale of ESPP shares/options exercise.
>
> Grt dt. Grt.type Ex. Dt Opt. ex. Opt. price FMV at ex Total gain
> 9/29/2002 Incentive 8/27/2004 3,125 $12.7054 $39,704.50
> 9/29/2002 Incentive 10/29/2003 520 $13.5990 $7,071.49 Total 48,203.34
> Reported in W-2 48,203.34
>
> I am using word 03 and excel 03
> Hope this makes sense.
> Thanks
>
>
>
>


Relevant Pages

  • RE: Sub report message
    ... performs the first join and then include that query in your SQL statement." ... Left join employee table to issue table. ... 1.I checked the main report query to see if there was a problem. ... All site staff are listed including all of the Food Service ...
    (microsoft.public.access.reports)
  • Re: Still Struggling...
    ... Dim rs As Object declares to the After Update event that rs is an Object. ... it's very different from a Bookmark in Word. ... report after I created that button. ... > I'm trying to do is create a drop-down list of employee last name,> first ...
    (microsoft.public.access.gettingstarted)
  • RE: Sub report message
    ... 1.I checked the main report query to see if there was a problem. ... All site staff are listed including all of the Food Service ... both employees have employee IDs that are not ... I assume it was referring to the IIF statement that you wanted me to place ...
    (microsoft.public.access.reports)
  • Re: Still Struggling...
    ... Dim rs as Object declares rs as an object variable. ... have only input 6 employee names using frmEmployees just so I can check to ... report after I created that button. ...
    (microsoft.public.access.gettingstarted)
  • RE: Sub report message
    ... appear in the key code section of the Site Employee report. ... the main and then in the Key Assignments query join the main query. ...
    (microsoft.public.access.reports)