How do I mail merge from Word to Outlook with merge subject field

A

Alex

HELP!!

I have a mass email I need to send with personalised contents from an Excel
database. I have created the merge from Word all fine, but now I need to
insert merge fiels into the email subject line - is this possible to do to
send from Word doc to Outlook?
 
P

Peter Jamieson

If you are familiar with VBA, you can use Word's MailMerge events and
VBA to specify the subject for each email.

e.g. in the VBA Editor, Insert a new Class Module, name it
EventClassModule, and insert the following code:

Public WithEvents App As Word.Application

Private Sub App_MailMergeBeforeRecordMerge(ByVal Doc As Document, Cancel
As Boolean)

' set this to be the exact name (uppercase/lowercase are significant
here) of the field you want to use
Const strSubjectFieldName = "mysubjectfield"
Doc.MailMerge.MailSubject = _
Doc.MailMerge.DataSource.DataFields(strSubjectFieldName).Value
End Sub

In an ordinary module, put the following VBA

'---
Dim x As New EventClassModule

Sub MergeWithEvents()

EnableEventHandler

' Do the merge
ActiveDocument.MailMerge.Execute Pause:=False

' The events fire for all documents
' so disable them
DisableEventHandler

End Sub

Sub EnableEventHandler()
Set x.App = Word.Application
End Sub

Sub EnableEventHandler()
Set x.App = Nothing
End Sub
'---

Then, with your mail merge main document open, run the MergeWithEvents
subroutine to run your merge

Peter Jamieson

http://tips.pjmsn.me.uk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top