' try matching the field name To accepted field names ' first check for the field being populated for the active record (row), only check if there is data provided ' run through all the fields in the mail merge data, when an email field is identified add the data To the appropriate field ' extract the "MailEnvelope" from the word doc, which is an outlook email containing the contents of the doc ' save the generated doc as a html file in the temp directory Mm.DataSource.LastRecord = mm.DataSource.ActiveRecord Mm.DataSource.FirstRecord = mm.DataSource.ActiveRecord ' use mailmerge To create a new document for one record (defined by mm.DataSource.ActiveRecord) ' set fields To be populated for each email Mm.DataSource.ActiveRecord = wdFirstRecord LastRecordNum = mm.DataSource.ActiveRecord Mm.DataSource.ActiveRecord = wdLastRecord ' if records are unchecked then the last record may not equal the record count ' go To the last record and record the record number Set outlookApp = CreateObject("Outlook.Application") ' use late binding so that if the reference is not added there is not an error ' set outlookApp which is used To control outlook To send an email VbYesNoCancel + vbDefaultButton2 + vbQuestion, "Send Emails")Ī(1).Select "Click 'Yes' To send the emails immediately, 'No' To save the emails in draft, and 'Cancel' To abort.", _ "Macro will ignore records that have been unchecked in the 'Edit Recipients' dialog box." & vbLf & vbLf & _ Select Case MsgBox("MailMerge To email has found " & mm.DataSource.RecordCount & " records." & vbLf & vbLf & _ ' Give the user an opportunity To abort, and also the option To save the emails in drafts, or send immediately , vbOKOnly + vbCritical, "Error") = vbOK Then Exit Sub VbLf & vbLf & "Please click the Edit Recipient List button To confirm that mail merge is correctly setup for this document." _ If MsgBox("Mailmerge not set up for active document - cannot perform mailmerge. ' check for the mail merge state being that of a mail merge ready To go ' identify the mail merge of the active document ' Please make sure you copy all the text in this code snippit box, including the function "StripToLcaseLetters" below this sub.ĭim outlookApp As Object 'Outlook.Applicationĭim outlookMail As Object 'Outlook.MailItemĭim outlookAccount As Object 'Outlook.Account ' Please share freely while retaining attribution Multiple To, CC, BCC and Attachment columns can be used.Omitting a field or leaving it blank will leave that field in the email as the default value.Attachment is the full file path of an attachment.SendAs is the email address of the person or team from which the email should appear to be sent from, or sent on behalf of.Account is the email address of the account from which the email is to be sent (not send as, see below).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |