If you want to set certain Outlook fields when you do a mail merge, you need to use an ItemSend rule.
To use, open the VBA Editor using Alt+F11 and expand Project1 until you see ThisOutlookSession. Double click on ThisOutlookSession and paste the macro in the right pane.
Updated July 26 2017: Changed the macro to use a codeword in the subject and remove the codeword before sending.
This macro is not limited to mail merges; it checks the subject of every message you send to see if it meets the condition of the If statement.
To avoid running the macro on all messages you send, I'm using a codeword in the subject. If the word is found, Outlook removes it from the subject and runs the macro on the messages, adding attachments and setting other fields as needed.
If you want to change the codeword, choose something unique that you would not expect to use in an email. Remember: the codeword is case-sensitive. What you use in the macro is also what you'll use in the subject field.
If you are setting a reminder, you'll want change the reminder date and time. You can set the reminder to a specific date and time using #10/30/2012 8:00:00 AM# format or use Now + 1 for this time tomorrow (or any number of days in the future). If you use the deferred delivery option, you can use SendAt + 1 to set a reminder for 24 hours after the deferred send time.
Recipients may have rules to remove the reminder, flag, and Importance fields.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) If InStr(LCase(Item.Subject), "[merge]") Then 'Defer delivery time SendAt = DateSerial(Year(Now), Month(Now), Day(Now) + 1) + #7:00:00 AM# With Item .Subject = Replace(.Subject, "[merge]", "") .Importance = olImportanceHigh .VotingOptions = "I accept;I decline;I don't care" .ReminderSet = True .ReminderTime = SendAt + 1 '#10/30/2012 8:00:00 AM# .FlagRequest = "Please reply by " & .ReminderTime .DeferredDeliveryTime = SendAt ' to add an attachment, enter the path & name here .Attachments.Add "C:\Users\username\Documents\TEST.xlsx" End With End If End Sub
If you want to use a different attachment for each person, you'll need to use attachments that are the same name as a message field - the To field will probably be the easiest, although prone to problems. ("To" is the display name, not the email address.)
Item.Attachments.Add "D:\For merge\" & Item.To & ".docx"
Or use one of the utilities listed at Using Mail Merge in Outlook
Quick help for anyone encountering the same problem:
The code word (["merge"]) needs to be written in small letters within the MS visual basic. Otherwise it will not work.
Thank you very much for this.
You saved me spending £30 on a plugin to do the same!
This is so great.. and can we attach more than 1 file?
and how to edit this command, if we want to send it immediately?
Many thanks.
Remove the line to send immediately.
Repeat this line for each attachment - changing the path of course. :0
.Attachments.Add "C:\Users\username\Documents\TEST.xlsx"
This is great but what would the syntex be to add the BCC field and email addresses under with item in the macro?
I would also really appreciate to learn how to do this as well
found this which forces a BCC. Its not as elegent as this though. Wondering if its possible to combine them...
https://www.slipstick.com/outlook/email/automatically-bcc-all-message/
Diane, I am trying to add the same attachment to multiple emails that are cued up in my outbox on outlook. I am trying to figure out a way to add the attachments through outlook or, preferably, I would like to add the attachments as part of the mail merge, before I merge the emails from Word into my Outlook outbox. I'm not familiar with macros/VBA so I wasn't able to get anywhere with some of the replies you had provided to similar questions. Would really appreciate any guidance! Thanks. P.S. I am on a Mac.
The PS part is the problem - Outlook for Mac doesn't use VBA. You'll need to do it in apple script - but I have very limited knowledge of apple script.
Hi Diane, firstly thank you the video clip made it easy to understand and the use of a keyword was quite ingenious. I am not a VBA programmer, I've cut down your original code and am trying to use the code with a different email account which I have permission for in Outlook 2016. Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) If InStr(LCase(Item.Subject), "[merge]") Then With Item .Subject = Replace(.Subject, "[merge]", "") ' to add an attachment, enter the path & name here .Attachments.Add "C:\Users\username\Documents\TEST.xlsx" 'You can use .SentOnBehalfOfName property of outlook to send mail in the name of other user .SentOnBehalfOfName = "user@domain.com" .Display .Send End With End If End Sub At the moment the sent on behalf will only work if I take Outlook offline and physically open the email then manually send it, then go back online. Ideally, I don't want there to be any need for manual intervention. I've read up a bit and other posts say that the command SentOnBehalfOfName needs to be set first, in all the other examples it has been done in the context of creating something new, I can't work out the correct syntax for this code as it… Read more »
HI Diane - thanks for this! For some reason my subject line is still featuring [merge]. Could you help me figure out what I'm doing wrong?
.Subject = Replace(.Subject, "[merge]", "") is what I'm using in my code. Thanks!
[merge] user for mail merge when you doing mail merge
Diane: I have copied the vba text as shown above in my Outlook sessions and even put the test .xlsx file in the file you show in the video. Obviously, I am doing something incorrectly, because it sends immediately instead of going to my Outbox and the attachment is never attached. I have about 200 e-mails that need the same attachment so I it would be helpful if I could get this to work. I have Outlook 2010 and Windows 10.