• 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
Post Views: 38

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.

Comments

  1. Valerie says

    June 4, 2020 at 12:15 pm

    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?

    Reply
    • Eric says

      January 17, 2023 at 4:13 pm

      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

      Reply
    • Eric says

      January 18, 2023 at 1:10 pm

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

      Reply
  2. Philip Coltharp says

    December 10, 2019 at 3:51 pm

    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.

    Reply
  3. Michael Vejda says

    April 18, 2019 at 4:06 am

    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

    Reply
  4. Courtney says

    May 22, 2017 at 9:39 am

    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!

    Reply
    • Diane Poremsky says

      May 23, 2017 at 12:31 am

      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

      Reply
    • Courtney says

      May 23, 2017 at 9:51 am

      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.

      Reply
      • Diane Poremsky says

        May 24, 2017 at 4:35 pm

        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

  5. KMReavis says

    April 4, 2016 at 1:29 pm

    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?

    Reply
    • Diane Poremsky says

      April 18, 2016 at 8:57 am

      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

      Reply
  6. Martin Dickerson says

    January 29, 2016 at 3:07 am

    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
    Dim objAttachments As Outlook.Attachments
    Dim strFile As String
    Dim strDirectory As String

    For Each obj In ActiveExplorer.Selection
    Set objMail = obj
    Set objAttachments = objMail.Attachments
    strDirectory = "C:\Temp\"
    ' Print email
    objMail.PrintOut
    ' Print email attachments
    If objAttachments.Count Then
    For Each objAttachment In objAttachments
    strFile = strDirectory & objAttachment.FileName
    objAttachment.SaveAsFile strFile
    ShellExecute 0, "print", strFile, vbNullString, vbNullString, 0
    Next
    End If
    Next

    ' Confirm message
    'Dim OutPut As Integer
    OutPut = MsgBox("Email attachments printed.", vbInformation, "Print Email Attachments")

    ' Cleanup
    Set objMail = Nothing
    Set objAttachments = Nothing

    End Sub

    Reply
    • Diane Poremsky says

      January 29, 2016 at 2:26 pm

      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.

      Reply
      • Martin Dickerson says

        January 30, 2016 at 2:05 am

        Thankyou Diane that's brilliant :-)

  7. Hiep Nguyen says

    September 5, 2015 at 5:00 am

    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

    Reply
    • Diane Poremsky says

      September 5, 2015 at 11:53 pm

      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

      Reply
  8. peterrhawkes says

    August 16, 2015 at 8:17 am

    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

    Reply
    • Diane Poremsky says

      August 17, 2015 at 12:52 am

      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.

      Reply
  9. peterrhawkes says

    August 15, 2015 at 5:53 am

    No luck I am afraid?

    Reply
    • Diane Poremsky says

      August 15, 2015 at 8:21 pm

      I haven't been able to repro that error - if Microsoft word 16.0 Object Library is not selected, I get user defined type not defined error. if you have more than one version of word installed, make sure you have the 16.0 object library selected. Select it - what is the path at the bottom of the dialog?

      Are you using the public preview or are you in the enterprise preview and have the msi installed? It shouldn't matter, but t seems to say it can't find the library.

      Reply
  10. peterrhawkes says

    August 14, 2015 at 3:58 am

    Getting Compile error on wdStory 'Cant find project or library'. Have Word 2016 Object loaded. Using Outlook 2016

    Reply
    • Diane Poremsky says

      August 14, 2015 at 11:17 pm

      That error should point to the word object library - try deselecting it and reselecting it.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

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

Latest EMO: Vol. 31 Issue 7

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
  • Reset the New Outlook Profile
  • Disable "Always ask before opening" Dialog
  • This operation has been cancelled due to restrictions
  • How to Hide or Delete Outlook's Default Folders
  • Change Outlook's Programmatic Access Options
  • Use Public Folders In new Outlook
  • Removing Suggested Accounts in New Outlook
  • How to Delete Stuck Read Receipts
  • Sync Issues and Errors with Gmail and Yahoo accounts
  • Error Opening iCloud Appointments in Classic Outlook
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
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

Sync Issues and Errors with Gmail and Yahoo accounts

Error Opening iCloud Appointments in Classic Outlook

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

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 © 2026 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.