• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Add Attachment Names to Message Before Sending

Slipstick Systems

› Developer › Code Samples › Add Attachment Names to Message Before Sending

Last reviewed on May 23, 2017     22 Comments

Ella saw my macro that adds attachment names to the reply and asked about a macro that will add the attachment names to the message body before sending:

When I write an email (with attachments) and send it to someone it would be very helpful to have Outlook automatically include a list of the attachments (filenames) at the beginning of my email text body before finally sending it out.
This way the recipient cannot accidently miss/overlook the attachment when I do not specifically mention it in the email. When the recipient replies with my original message included I can quickly check what attachments I included with my first email without looking it up in the "sent mail". When including a bunch of attachments (let's say 10 jpg pictures) the recipient overlooks the last attachments and is not aware of them since there is no complete list in the text body.

It's actually fairly easy to convert the Reply macro to work with an ItemSend macro to do this as the message is sent, or you could run the macro manually before sending.

As the message is sent, the ItemSend macro checks for attachmwents and if one or more are found, it calls the AddAttachmentNames macro that adds the filenames to the message body. If you include images in your signature, you can skip smaller attachments by uncommenting the lines that check the file size.

insert filename in messages you send

To test the macro, send a message that has attachments.

This macro goes in ThisOutlookSession

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If Item.Attachments.Count > 0 Then
  AddAttachmentNames Item
End If
End Sub

This macro goes in a Module. Right click on ThisOutlookSAession and choose Insert, Module to add a new module.

You'll need to set a reference to the Word Object Library in the VBA Editor's Tools, Reference dialog.
tools-references-2016

Public Sub AddAttachmentNames(oItem As MailItem)

Dim oAtt As Attachment
Dim strAtt As String
    Dim olInspector As Outlook.Inspector
    Dim olDocument As Word.Document
    Dim olSelection As Word.Selection

strAtt = ""
 
For Each oAtt In oItem.Attachments
  ' If oAtt.Size > 5200 Then
    strAtt =  strAtt & " <<" & oAtt.FileName & ">> "
  ' End If
Next oAtt
      
    Set olInspector = Application.ActiveInspector()
    Set olDocument = olInspector.WordEditor
    Set olSelection = olDocument.Application.Selection
 
  olSelection.HomeKey Unit:=wdStory
 olSelection.InsertBefore "See attachments: " &strAtt & vbCrLf & vbCrLf
 
Set oItem = Nothing
End Sub

If you want to run the macro manually on specific messages, replace the sub name with the following two lines.

Public Sub AddAttachmentNames()
Dim oItem As MailItem

Then add these lines before strAtt = ""

Set oItem = Application.ActiveInspector.CurrentItem
If oItem.Attachments.Count = 0 Then
Exit Sub
End If

To make it easier to run the macro, add a macro button to the compose mail form window.

Add Attachment Names to Message Before Sending was last modified: May 23rd, 2017 by Diane Poremsky

Related Posts:

  • Copy attachment names when replying
  • Log Messages and Attachment Names
  • Remove Attachments From Messages
  • Use this macro to send an attachment to email addresses in the To line
    VBA: No attachments to CC'd recipients

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
22 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Valerie (@guest_215336)
June 4, 2020 12:15 pm
#215336

Hi there - I know this is an old discussion, but I get a run time error (91) when replying to a message with attachments. Any way to fix this?

0
0
Reply
Eric (@guest_219987)
Reply to  Valerie
January 17, 2023 4:13 pm
#219987

This is happening to me as well - were you able to figure this out? It's specific to this line of the code: Set olDocument = olInspector.WordEditor

0
0
Reply
Eric (@guest_219995)
Reply to  Valerie
January 18, 2023 1:10 pm
#219995

Were you able to resolve this? I'm running into the same issue.

0
0
Reply
Philip Coltharp (@guest_214460)
December 10, 2019 3:51 pm
#214460

To show more gratitude, I'm sharing this. I wanted to have my attachment list show after my signature. So I found code that let me do search and replace in the editor object. When I send an e-mail, the attachment list is created (thank you Diane) and then its "positioned" where I've prepared my special {{attachment list}} tag inside either of my two signatures, through the magic of search-and-replace.

0
0
Reply
Michael Vejda (@guest_213116)
April 18, 2019 4:06 am
#213116

Very nice little helper. Just one additional note, as I realized when I send Outlook invites with attachment an error occurs. Therefore I limited the part in ThisOutlookSession to mail items (olMail) only:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If Item.Attachments.Count > 0 And Item.Class = olMail Then
AddAttachmentNames Item
End If
End Sub

I anyhow do not need to write attachment names in outlook invites. So this solution works fine with me.

Michael

0
0
Reply
Courtney (@guest_206662)
May 22, 2017 9:39 am
#206662

Hi Diane!

This works great! Could you please help me modify to: 1) list below message body just above signature...below signature would be fine too, and 2) format it (e.g. bold and italicized)?

I do not know VBA at all, but I tried changing InsertBefore to Insert After...that did not work. I've tried to look at other formatting macros to piece together the formatting, but I'm coming up #fail.

Thanks a lot!

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Courtney
May 23, 2017 12:31 am
#206677

putting it at the very end is easy - putting it before or immediately after the signature is more difficult as you need to find the signature. Formatting is easy - it uses standard html (use ' instead of " in the styles) and may need to use HTMLBody. You could also select it and inserting and apply formatting using word code.
olSelection.InsertBefore "See attachments: " &strAtt & "" & vbCrLf & vbCrLf

to move it to the end, you use word code - olSelection.EndKey Unit:=wdStory, Extend:=wdExtend

0
0
Reply
Courtney (@guest_206691)
Reply to  Courtney
May 23, 2017 9:51 am
#206691

Also, the script works great! But I'm getting a run-time error "13 - type mismatch" when I try to forward meeting invites w an attached invite.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Courtney
May 24, 2017 4:35 pm
#206743

You only get it on meetings? This line: Public Sub AddAttachmentNames(oItem As MailItem) tells it the item is an mail item. Although you mail meeting requests, they are not mailitems. You could try using oitem as object or an if statement to only use mail items. Put this at the top of the application_itemsend macro.
If Item.MessageClass <> "IPM.Post" Then
Exit Sub
End If

0
0
Reply
KMReavis (@guest_197632)
April 4, 2016 1:29 pm
#197632

This is great. I know nothing about VBA/macros. Your instructions were clear. I did have to enable macros to run and deactivate DEP. It works perfectly. However, how can I modify the code so that the "see attachments" text is at the bottom of the message?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  KMReavis
April 18, 2016 8:57 am
#197953

Try changing insertbefore to insertafter. (I actually forget if that will work, but if not, there are other ways to do it.)
olSelection.HomeKey Unit:=wdStory
olSelection.InsertBefore "See attachments: " &strAtt & vbCrLf & vbCrLf

0
0
Reply
Martin Dickerson (@guest_196180)
January 29, 2016 3:07 am
#196180

Hi Diane Firstly, let me say how much I love your site. It’s taught me a lot about MS Outlook macros and VBA. I have used your code "Print Attachments on Selected Messages" to create a macro to print both an email and its attachments and it’s working great! I was wondering, however, how I might print a list of the attachments so that I can check that all the attachments were printed. Ideally I would like to modify the macro to (1) print the email, (2) print a list of the attachments, and then (3) print each attachment. If you have any ideas, I would be so grateful. Regards Martin Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias _ "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters As String, _ ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long Sub PrintEmailAttachments() ' Confirmation message Dim OutPut As Integer OutPut = MsgBox("Do you want to print the email attachments?", vbYesNo + vbQuestion + vbDefaultButton2, "Print Email Attachments") If OutPut = 7 Then Exit Sub End If ' Declare variables Dim objMail As Outlook.MailItem Dim obj As Object Dim objAttachment As Outlook.Attachment… Read more »

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Martin Dickerson
January 29, 2016 2:26 pm
#196188

to get a list of names you'll add
For Each objAttachment In objAttachments
strAtt = strAtt & objAttachment .FileName
Next objAttachment
then you just need to insert it in a file and print.

The sample at https://www.slipstick.com/developer/macro-send-files-email/ shows how to include a file name in a message - although it would probably be better to save it in a text file and print. The second macro at https://www.slipstick.com/developer/code-samples/save-email-message-text-file/ shows how to write data to a text file.

0
0
Reply
Martin Dickerson (@guest_196204)
Reply to  Diane Poremsky
January 30, 2016 2:05 am
#196204

Thankyou Diane that's brilliant :-)

0
0
Reply
Hiep Nguyen (@guest_193126)
September 5, 2015 5:00 am
#193126

Dear Diane Poremsky,
I learned a lot from your post and deeply appreciated for that.
Please advise me how to save attachment(s)that attached in email into my local folder such as “C:\AttachmentSent\” before sending email automatically.
I just want to keep copies of attachment files that I sent out as back-up copies.
Best regards,
Nguyen

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Hiep Nguyen
September 5, 2015 11:53 pm
#193139

you would use code like this - this example uses an Attachments folder under the user's documents folder, but you can change the path used in strFolderPath as needed.
strAtt = strAtt & " <<" & oAtt.FileName & ">> "
Dim strSavePath As String
strSavePath = CreateObject("WScript.Shell").SpecialFolders(16) & "\Attachments\"
oItem.Attachments.Item(1).SaveAsFile strSavePath & oAtt.FileName

0
0
Reply
peterrhawkes (@guest_192617)
August 16, 2015 8:17 am
#192617

The version loaded is as offered from my 365 Business Account. Path to Microsoft Word 16.0 object library is c:\Program Files\ Microsoft Office\Root\Office16\MSWORD.OL

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  peterrhawkes
August 17, 2015 12:52 am
#192625

That's the 64bit version? I wonder if that is the problem - most macros work fine with 64bit but a few need tweaked for 64bit.

0
0
Reply

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

Latest EMO: Vol. 30 Issue 16

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
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Disable "Always ask before opening" Dialog
  • This operation has been cancelled due to restrictions
  • Adjusting Outlook's Zoom Setting in Email
  • How to Hide or Delete Outlook's Default Folders
  • Reset the New Outlook Profile
  • Save Attachments to the Hard Drive
  • Outlook SecureTemp Files Folder
  • Add Attachments and Set Email Fields During a Mail Merge
  • 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