' if field is not provided, or an incorrect input value is provided, then the default is used ' change the importance, accepted input values are "high", "normal", and "low" (not case sensitive) ' add in the subject as it is presented in the dataĮrrorString = "Second subject field found containing: " & df.Value ' add in the bcc address or addresses as they are presented in the data, if multiple BCC fields are present they will all be added, separated by a semicolonĮrrorString = errorString & vbCrLf & "Invalid email address in BCC field: " & df.Value ' add in the CC address or addresses as they are presented in the data, if multiple CC fields are present they will all be added, separated by a semicolonĮrrorString = errorString & vbCrLf & "Invalid email address in CC field: " & df.Value If InStr(1, df.Value, vbBinar圜ompare) > 0 ThenĮrrorString = errorString & vbCrLf & "Invalid email address in To field: " & df.Value ' add in the To address or addresses as they are presented in the data, if multiple To fields are present they will all be added, separated by a semicolon ' 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).FollowUp is used to flag the message for a follow up – if a number is provided in this column it indicates the number of days from today for the follow up, if date (in the future) is provided the follow up will be on that date.DeliveryTime can be a datetime, a date (email will be sent at midnight on that date) or time (email will be sent at next instance of the specified time).ReadReceipt and DeliveryReceipt can be true, yes or y to request, or false, no or n to not request.Sensitivity can be normal, personal, confidential, and private.Subject can be whatever you want, and individualised to the recipient.To, CC and BCC should contain email addresses separated by a semi-colon (multiple columns can be used if preferred).Add any of the following columns to your Mail Merge data: To, CC BCC, Subject, Importance, Sensitivity, ReadReceipt, DeliveryReceipt, DeliveryTime,FollowUp, Account, SendAs, Attachment.Copy the text of the Macro from below and add to Word.
0 Comments
Leave a Reply. |