Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
I am trying to send individual emails to my 25 recipients, and attach to each
the mail-merged form letter. I manage to get that done, but would like there to be wording in the body of the email to let the recipient know what the attachment is about (recipients do not know me...yet!) Its not unlike I'm trying to send my resume out, and the cover letter is the attachment. Can I add text to the email once I've attached the mail merge document? |
#2
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
If you are using the full Outlook, you can try the following Word VBA
approach (not very well tested!): Each email can only "consume" one record in the data source - i.e., no NEXT/NEXTIF fields etc.. Graham Mayor has some instructions for installing and running VBA at http://www.gmayor.com/installing_macro.htm Sub EmailOneDocPerSourceRecWithBody() 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, "to" and "cc" ' Just some sample code here - replace it with ' whatever you need. But ensure that the field names ' match the ones in your data source exactly - uppercase/lowercase ' differences are significant here 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 mail item Set objMailItem = objOutlook.CreateItem(olMailItem) With objMailItem .Subject = strMailSubject .Body = strMailBody .To = strMailTo .CC = strMailCC .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 Peter Jamieson http://tips.pjmsn.me.uk On 21/02/2010 19:41, Bibbi wrote: I am trying to send individual emails to my 25 recipients, and attach to each the mail-merged form letter. I manage to get that done, but would like there to be wording in the body of the email to let the recipient know what the attachment is about (recipients do not know me...yet!) Its not unlike I'm trying to send my resume out, and the cover letter is the attachment. Can I add text to the email once I've attached the mail merge document? |
#3
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
See the article prepared by fellow MVP Doug Robbins at
http://word.mvps.org/FAQs/MailMerge/...ttachments.htm and http://www.gmayor.com/EmailMergeWithAttachments.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org "Bibbi" wrote in message news ![]() I am trying to send individual emails to my 25 recipients, and attach to each the mail-merged form letter. I manage to get that done, but would like there to be wording in the body of the email to let the recipient know what the attachment is about (recipients do not know me...yet!) Its not unlike I'm trying to send my resume out, and the cover letter is the attachment. Can I add text to the email once I've attached the mail merge document? |