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