View Single Post
  #4   Report Post  
Posted to microsoft.public.word.newusers,microsoft.public.word.vba.general
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default VBA code to execute for a subsequent mail merge

The directory type mailmerge and the macro amounts to re-doing the data
source.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Colonel Blip" wrote in message
...
Hello, Doug!
You wrote on Tue, 5 Sep 2006 21:50:24 +0200:

Maybe I'm missing a point here, but it seems to do what you're suggesting
means setting up a 2 step merge process. I will admit right now I enough
of a novice in this stuff that I may not be able to see where you are
going (or better yet, where I am going g) with this approach. FWIW, here
is the alternative that I know will work but requires redoing the contact
data base to have First_Name contain one name and have the Spouse filed
have the second name.

{ INCLUDEPICTURE "O:\\TEMP\\{ Mergefield "Full_Name" }.JPG" }


{ IF { MERGEFIELD Last_Name } = "Wonderful" "Sue & " "" }{ MERGEFIELD
"First_Name" }{ IF { MERGEFIELD Spouse } "" " & " "" }{ MERGEFIELD
"Spouse" }{ IF { MERGEFIELD Middle_Name } "" " " "" }{ MERGEFIELD
"Middle_Name" } { MERGEFIELD "Last_Name" }{ IF { MERGEFIELD Full_Name } =
"Jane Doe" " (with John Doe)" "" }

{ MERGEFIELD "Children" }
{ MERGEFIELD "Business_Address" }
{ IF { MERGEFIELD Home_Phone } "" "Home: " "" }{ MERGEFIELD
"Home_Phone" }
{ IF { MERGEFIELD Business_Phone } "" "Work: " "" }{ MERGEFIELD
"Business_Phone" }
{ IF { MERGEFIELD Mobile_Phone } "" { MERGEFIELD "First_Name" } "" }{
IF { MERGEFIELD Mobile_Phone } "" " Cell: " "" }{ MERGEFIELD
"Mobile_Phone" }
{ IF { MERGEFIELD Other_Phone } "" { MERGEFIELD "Spouse" } "" }{ IF {
MERGEFIELD Other_Phone } "" " Cell: " "" }{ MERGEFIELD "Other_Phone" }
{ IF { MERGEFIELD Email } "" "" }{ MERGEFIELD "Email" }
{ IF { MERGEFIELD Email_2 } "" "" }{ MERGEFIELD "Email_2" }
{ IF { MERGEFIELD Email_3 } "" "" }{ MERGEFIELD "Email_3" }
{ IF { MERGEFIELD Last_Name } = "Wise" "Jane Cell: (123) 123-4567" "" }

Thanks,

Colonel Blip.
E-mail:

DRW You could use your data source with a directory type mail merge main
DRW document in which you insert the mergefields into the cells of a one
DRW row table. When you execute the merge to a new document, that
DRW document will contain a table with a row of data for each record in
DRW the data source. You could then insert a new column into the table
DRW and run a macro that iterated through the cells in the column
DRW containing the first names and if there was a & in the data in the
DRW cell, split the data so that part of it would remain in the cell and
DRW the other part would be moved into the adjacent cell in the new
DRW column. Then you could insert a row at the top of the table and into
DRW the cells of that row, insert field names to be used when merging
with
DRW that file as the data source.

DRW The following code will do the splitting of the names (assuming that
DRW they are in column 1 and that you insert the new column to the right
DRW of it so that it becomes column 2

DRW Dim i As Long, j As Long
DRW Dim drange As Range
DRW With ActiveDocument.Tables(1)
DRW For i = 1 To .Rows.Count
DRW Set drange = .Cell(i, 1).Range
DRW j = InStr(drange, "&")
DRW If j 0 Then
DRW drange.Start = drange.Start + j + 1
DRW drange.End = drange.End - 1
DRW .Cell(i, 2).Range.Text = drange.Text
DRW drange.Start = drange.Start - 3
DRW drange.Delete
DRW End If
DRW Next i
DRW End With