Email merge not including the header of the letter

T

Tammy

Hi,

I posted this to the Outlook group first, and they told me to post the
question in the Word group. Here is the post:

Hi,

I wasn't sure if this should be posted in the Word group, or Outlook. If I
should repost to the Word group, please let me know.

I have a user who is trying to send out a mail merge letter using a template
she created, which includes a header, as the main document. The source is her
Outlook Contacts folder. The email goes out, but the header is not included
in the email message.

Can a header from a letter be included with an email merge? If so, how can I
do this?

Is there a way to make sure the entire letter, including a header and
footer, gets sent through an email?

If not, do you have any other suggestions? The letter is personalized during
the mail merge process, so we can't attach a "generic" letter to the email.

Thanks!
 
T

Tammy

Update - my user is not using her Outlook contacts. She is creating an email
merge in Word, and using an Access query as her contact source. I
experimented with OL contacts, and it did not work, so I know the contact
source doesn't have anything to do with this. I have a feeling this is going
to be a "can't be done" answer.

Thanks for any suggestions!
 
P

Peter Jamieson

Word mailmerge "out of the box" does the following:
a. fills in the fields in your mail merge main document, and sends that
..doc(x) as an attachment to a mail merge message. That mail merge message
has no body text - just recipient, subject, and the attachment
b. fills in the fields in your mail merge main document, and sends that as
the body of an HTML format e-mail. This only works if you are sending the
emails via Outlook (not Outlook Express)
c. fills in the fields in your mail merge main document, coverts the doc.
to plain text and sends that text as the body of a plain text format e-mail
message

Of these, only (a) can give you headers and footers in the normal word
processing sense of the word, but (1) you have that empty message body and
(2) the recipient has to have some way to open a Word format document (e.g.
the word reader). Neither (b) nor (c) can do headers/footers - that's a
limitation of the mail format, not Word.

Doing anything else requires that you either
a. use VBA macros (or some other programming approach) to prepare the
emails and send them. That lets you attach the merged document /and/ insert
some text in the body of the document.
b. use a third party solution/add-on of some kind

For (a) you can use a macro like this:

Sub EmailOneDocPerSourceRecWithBody()
' By Peter Jamieson, 2006
Dim bOutlookStarted As Boolean
Dim bTerminateMerge As Boolean
Dim intSourceRecord As Integer
Dim objMailItem As Outlook.MailItem
Dim objMerge As Word.MailMerge
Dim objOutlook As Outlook.Application
Dim strMailSubject As String
Dim strMailTo As String
Dim strMailBody As String
Dim strOutputDocumentName As String


bOutlookStarted = False
bTerminateMerge = False


' Set up a reference to the
' Activedocument, partly because
' the ActiveDocument changes as you
' merge each record


Set objMerge = ActiveDocument.MailMerge


' Start Outlook as necessary


On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set objOutlook = CreateObject("Outlook.Application")
bOutlookStarted = True
End If


With objMerge


' If no data source has been defined,
' do it here using OpenDataSource.
' But if it is already defined in the
' document, you should not need to
' define it here.


' .OpenDataSource _
' Name:="whatever"


intSourceRecord = 1


Do Until bTerminateMerge
.DataSource.ActiveRecord = intSourceRecord


' if we have gone past the end
' (and possibly, if there are no records)
' then the Activerecord will not be what
' we have just tried to set it to


If .DataSource.ActiveRecord <> intSourceRecord Then
bTerminateMerge = True
' the record exists
Else


' while we are looking at the
' correct activerecord,
' create the mail subject, body and "to"
' Just some sample code here - replace it with
' whatever you need


strMailSubject = _
"Results for " & _
objMerge.DataSource.DataFields("Firstname") & _
" " & objMerge.DataSource.DataFields("Lastname")


strMailBody = _
"Dear " & objMerge.DataSource.DataFields("Firstname") & _
vbCrLf & _
"Please find attached a Word document containing" & vbCrLf & _
"your results for..." & vbCrLf & _
vbCrLf & _
"Yours" & vbCrLf & _
"Your name"
strMailTo = objMerge.DataSource.DataFields("Emailaddress")


' create the document path name
' In this case it can be the same for every recipient,
' but if you want to retain copies of the
' document, you can use info. in the data source


' this is an example - insert your
' own pathname here


strOutputDocumentName = "c:\a\results.doc"


' strOutputDocumentName = _
' "c:\mymergeletters\_" & _
' .DataSource.DataFields("Lastname").Value & _
' " letter.doc"
.DataSource.FirstRecord = intSourceRecord
.DataSource.LastRecord = intSourceRecord
.Destination = wdSendToNewDocument
.Execute


' The Activedocument is always the
' output document


' Add any parameters you need to these calls
ActiveDocument.SaveAs strOutputDocumentName
ActiveDocument.Close


' Now create a


Set objMailItem = objOutlook.CreateItem(olMailItem)
With objMailItem
.Subject = strMailSubject
.Body = strMailBody
.To = strMailTo
.Attachments.Add strOutputDocumentName, olByValue, 1
'.Save
.Send
End With
Set objMailItem = Nothing


intSourceRecord = intSourceRecord + 1
End If
Loop
End With


' Close Outlook if appropriate


If bOutlookStarted Then
objOutlook.Quit
End If


Set objOutlook = Nothing
Set objMerge = Nothing


End Sub
 
T

Tammy

Hi Peter,

Thanks so much for your very informative response. I really appreciate all
the coding you provided. You answered my question and more!

Thanks, again!
 
T

Tammy

Hi Peter,

Sorry if this gets posted twice - an error occurred when I tried sending it
the first time.

Thanks so much for your very informative response. I really appreciate all
the coding you provided. You answered my question and more!

Thanks, again!
 

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