View Single Post
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Greeting line for contacts with two names

It is not possible to parse such a field in Word. You would have to make
use of (and enter the desired greeting line data) into one of the other
fields (nickname is one that you could use) that are available in Outlook.

The only other way would be to execute the merge to a new document and then
use a macro to go through that document, setting a Range object to the
..Range of the paragraph that contains the data from the Full Name field and
modifying the text in that field. The following code will do that if the
FullName mergefield is the only thing in the First Paragraph of the
mailmerge main document. (It prepends the names with the "Dear ", so it is
not necessary to have that in the mail merge main document

Dim i As Long
Dim fullname As Range
Dim Name2 As Range
Dim fname1 As Range, fname2 As Range
With ActiveDocument
For i = 1 To .Sections.Count
Set fullname = .Sections(i).Range.Paragraphs(1).Range
If InStr(fullname, " and ") 0 Then
Set Name2 = fullname.Duplicate
Set fname1 = fullname.Duplicate
Name2.Start = Name2.Start + InStr(Name2, "and") + 3
Set fname2 = Name2.Duplicate
If fullname.Words(2) = "-" Then
fname1.End = fullname.Words(3).End
Else
fname1.End = fullname.Words(1).End
End If
If Name2.Words(2) = "-" Then
Name2.End = Name2.Words(3).End
Else
Name2.End = Name2.Words(1).End
End If
fullname.Text = "Dear " & fname1 & "and " & Name2
Else
Set fname1 = fullname.Duplicate
If fullname.Words(2) = "-" Then
fname1.End = fullname.Words(3).End
Else
fname1.End = fullname.Words(1).End
End If
fullname.Text = "Dear " & fname1
End If
Next i
End With


--
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, originally posted via msnews.microsoft.com
"Portagepa" wrote in message
...
Coming from Outlook (2007); both names in the "Full Name" line.

"Doug Robbins - Word MVP" wrote:

Depends upon exactly what fields you have in the data source for the
names
of the people. Can you tell us what they are?

--
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, originally posted via msnews.microsoft.com
"Portagepa" wrote in message
...
If I have a couple with different last names as a Contact (Nancy Smith
and
Don Jones); any way to pick the first names up correctly in the
Greeting
line
in a mail merge? (Dear Nancy and Don).