• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • 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     52 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

Related Posts:

  • Mail Merge to Contact Groups
  • Mail merge and Send from a Distribution Group
  • 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
52 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Jerzy (@guest_221558)
December 19, 2024 7:08 am
#221558

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

If InStr(LCase(Item.Subject), "testtest") Then
'Defer delivery time
'SendAt = DateSerial(Year(Now), Month(Now), Day(Now) + 1) + #7:00:00 AM# - jutro o 7 rano
  SendAt = DateSerial(Year(Now), Month(Now), Day(Now))
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:\1\2024test.pdf"
End With
 End If
End Sub

I try & try
and do not work for office365n enterprice

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Jerzy
December 19, 2024 12:35 pm
#221559

Any error messages? What exactly happens?

It's working here.

I updated the file path to use a file in OneDrive and it failed because the attachment was not downloaded to the computer (only the shortcut). Once I downloaded it, it worked.

0
0
Reply
Kyle (@guest_220381)
June 30, 2023 3:56 pm
#220381

I am not having any luck at the moment. I've tried restarting outlook, but I'm still just receiving messages that say [merge] in the subject with no attachments. I've enabled all macros and can't seem to get any traction.

Here's the version of the code I'm using.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

If InStr(LCase(Item.Subject), "[merge]") Then
'Defer delivery time
  SendAt = Now + TimeSerial(0, 2, 0)
With Item
   .Subject = Replace(.Subject, "[merge]", "")
   .Importance = olImportanceHigh
   .DeferredDeliveryTime = SendAt
' to add an attachment, enter the path & name here
   .Attachments.Add "Z:\"FILENAME".pdf"
End With
 End If
End Sub

0
0
Reply
Yudhi (@guest_220361)
June 20, 2023 5:24 am
#220361

Hi Diane,

Thank you for your great code.

I have tried in Outlook 2013 and its work but not when I tried in Outlook 2019. Whats setting should I change?

0
0
Reply
Fahri pratomo (@guest_220303)
May 25, 2023 11:50 am
#220303

i did everything but still nothing happen, no attachment and the email keep being sent.
is this still working until today?

0
0
Reply
sam (@guest_220270)
May 10, 2023 11:36 am
#220270

Hi Diane - Thank you for this - ive tried adding SentOnBehalfOfName = "user@domain.com" but it doesnt work. Any suggestions please?

0
0
Reply
Ross (@guest_220137)
March 8, 2023 9:17 am
#220137

Could someone assist me with the following so that it will send individual attachments as mentioned above;

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
      .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

Where do I include this...
Item.Attachments.Add "D:\For merge\" & Item.To & ".pdf"

Also, is there a way to use an email vs the display name?

Thank you

0
0
Reply
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.

2
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

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

Latest EMO: Vol. 30 Issue 19

Subscribe to Exchange Messaging Outlook






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?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
  • Classic Outlook is NOT Going Away in 2026
Ajax spinner

Recent Bugs List

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

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

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

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

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.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

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

Other Microsoft 365 applications and services




New Outlook Articles

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Classic Outlook is NOT Going Away in 2026

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

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

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

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

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

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

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

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 | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 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