View Single Post
  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Mailmerge an address book with an Excel spreadsheet

It should be possible to add the relevant number to a custom field in the
Outlook record and merge directly from Outlook.

For example if you copy the Excel columns containing the e-mail addresses
and the numbers to a two column Word table (addresses in col 1) and save
that as a Word document (here "d:\My Documents\Test\email table.docx"), the
following *Outlook* Macro will add the relevant numbers to the Outlook
records that contain the e-mail addresses in the Email1Address field of
Outlook. The numbers will be stored in the Outlook field User3. This field
can then be included in your mail merge.

It should also be possible to lookup the entries directly from the Excel
table with a similar macro, but as I am less familiar with the Excel object
model I will stick to Word.


Public Sub AddNumberToUser3()
'Create this macro in OUTLOOK!
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objContactFolder As Outlook.MAPIFolder
Dim objContact As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim obj As Object
Dim oNum As Range
Dim strDoc As String
Dim oCell As Range
strDoc = "d:\My Documents\Test\email table.docx"
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err Then
Set wdApp = CreateObject("Word.Application")
End If
Set wdDoc = wdApp.Documents.Open(strDoc)
Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNamespace("MAPI")
Set objContactFolder = objNS.GetDefaultFolder(olFolderContacts)
Set objItems = objContactFolder.Items
For Each obj In objItems
If obj.Class = olContact Then
Set objContact = obj
With objContact
For i = 1 To wdDoc.Tables(1).Rows.Count
Set oCell = wdDoc.Tables(1).Cell(i, 1).Range
oCell.End = oCell.End - 1
If oCell.Text = .Email1Address Then
Set oNum = wdDoc.Tables(1).Cell(i, 2).Range
oNum.End = oNum.End - 1
.User3 = oNum.Text
.Save
Exit For
End If
Next i
End With
End If
Err.Clear
Next
Set objOL = Nothing
Set objNS = Nothing
Set obj = Nothing
Set objContactFolder = Nothing
Set objContact = Nothing
Set wdDoc = Nothing
Set wdApp = Nothing
End Sub


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



dfoxwe wrote:
Is it possible to merge an Outlook Address list with an Excel
spreadsheet? I would like to pull a number from a list of numbers and
match that to an individual email address. The goal is to have an
address merged with a unique number.