• Outlook User
  • Exchange Admin
  • Office 365
  • Outlook Developer
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
    • Common Problems
    • Outlook BCM
    • Utilities & Addins

Add Attachments and Set Email Fields During a Mail Merge

Slipstick Systems

› Developer › Code Samples › Add Attachments and Set Email Fields During a Mail Merge

Last reviewed on December 3, 2019     43 Comments

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.

after hitting send, the attachment and fields are added

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

Video Tutorial

More Information

Using Mail Merge in Outlook
Mass Mail Tools for Outlook
Printing Labels or Envelopes for Contacts
Start a Word letter from an Outlook contact
Create a Letter to a Contact using VBA

Add Attachments and Set Email Fields During a Mail Merge was last modified: December 3rd, 2019 by Diane Poremsky
  • Twitter
  • Facebook
  • LinkedIn
  • Reddit
  • Print

Related Posts:

  • Mail merge and Send from a Distribution Group
  • Mail Merge to Contact Groups
  • Mail Merge to Email using an Outlook Macro
  • Merge to email using only Outlook

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
43 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Hannes (@guest_219881)
November 24, 2022 11:51 am
#219881

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.

0
0
Reply
Paolo (@guest_219726)
September 19, 2022 9:22 am
#219726

Thank you very much for this.
You saved me spending £30 on a plugin to do the same!

0
0
Reply
Santos (@guest_219462)
June 23, 2022 5:04 am
#219462

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?

SendAt = DateSerial(Year(Now), Month(Now), Day(Now) + 1) + #7:00:00 AM#
With Item

Many thanks.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Santos
September 19, 2022 2:50 pm
#219727

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"

0
0
Reply
David manley (@guest_214957)
March 26, 2020 2:00 pm
#214957

This is great but what would the syntex be to add the BCC field and email addresses under with item in the macro?

1
0
Reply
nick (@guest_216110)
Reply to  David manley
October 23, 2020 3:42 pm
#216110

I would also really appreciate to learn how to do this as well

0
0
Reply
nick (@guest_216111)
Reply to  David manley
October 23, 2020 4:12 pm
#216111

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/

Last edited 2 years ago by nick
0
0
Reply
Rob Perkins (@guest_214939)
March 18, 2020 5:45 pm
#214939

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.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Rob Perkins
March 19, 2020 12:30 am
#214942

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.

0
0
Reply
Jeza (@guest_213666)
July 23, 2019 8:11 pm
#213666

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 »

0
0
Reply
Courtney S (@guest_213148)
April 24, 2019 4:24 pm
#213148

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!

0
0
Reply
Krunal Chauhan (@guest_213960)
Reply to  Courtney S
September 18, 2019 8:59 am
#213960

[merge] user for mail merge when you doing mail merge

0
0
Reply
Cathy M (@guest_211605)
July 27, 2018 2:49 pm
#211605

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.

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 28 Issue 11

Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Subscribe to Exchange Messaging Outlook






Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • WeekMonthAll
  • Adjusting Outlook's Zoom Setting in Email
  • How to Remove the Primary Account from Outlook
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Move an Outlook Personal Folders .pst File
  • Save Sent Items in Shared Mailbox Sent Items folder
  • Create rules that apply to an entire domain
  • Outlook's Left Navigation Bar
  • Use PowerShell to get a list of Distribution Group members
  • Remove a password from an Outlook *.pst File
  • View Shared Calendar Category Colors
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Change Appointment Reminder Sounds
  • Messages appear duplicated in message list
  • Reset the New Outlook Profile
  • Delete Old Calendar Events using VBA
  • Use PowerShell or VBA to get Outlook folder creation date
  • Outlook's Left Navigation Bar
  • Contact's Display Bug
  • Use PowerShell to get a list of Distribution Group members
  • Edit Outlook’s Attach File list
Ajax spinner

Newest Code Samples

Delete Old Calendar Events using VBA

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

Format Images in Outlook Email

Set Outlook Online or Offline using VBScript or PowerShell

List snoozed reminders and snooze-times

Search your Contacts using PowerShell

Filter mail when you are not the only recipient

Add Contact Information to a Task

Process Mail that was Auto Forwarded by a Rule

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in Outlook for Windows.

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




Windows 10 Issues

  • iCloud, Outlook 2016, and Windows 10
  • Outlook Links Won’t Open In Windows 10
  • Outlook can’t send mail in Windows 10: error Ox800CCC13
  • Missing Outlook data files after upgrading Windows?

Outlook Top Issues

  • The Windows Store Outlook App
  • The Signature or Stationery and Fonts button doesn’t work
  • Outlook’s New Account Setup Wizard
  • Outlook 2016: No BCM
  • Exchange Account Set-up Missing in Outlook 2016

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

Outlook-tips.net Samples

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

MSDN Outlook Dev Forum

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Contact Tools

Data Entry and Updating

Duplicate Checkers

Phone Number Updates

Contact Management Tools

Diane Poremsky [Outlook MVP]

Make a donation

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Outlook Suggestion Box (UserVoice)

Slipstick Support Services

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Advertise | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2023 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment