Copy attachment names when replying

Last reviewed on September 3, 2013

When you use RTF and Reply to a message that had attachments, the attachment names are added to the message body. When you use HTML or plain text messages the attachment name is not added to the message body.

It works like this for RTF messages because the attachments are embedded objects and that is how Outlook handles embedded objects. Unfortunately, using RTF is not practical because it results in winmail.dat file attachments and a general mess for any recipients not using Outlook.

This code works with Outlook 2013 (with inline reply disabled or when you reply from an opened message), and should work with Outlook 2010 and 2007. It might work with older versions if Word is set as the editor.

Insert the image name into a reply or reply all

How to use this macro

This macro "watches" for you to click the Reply or Reply All button and adds the filename to the top of the reply.

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To use the macro code in ThisOutlookSession:

  1. Expand Project1 and double click on ThisOutlookSession.
  2. Copy then paste the macro into ThisOutlookSession. (Click within the code, Select All using Ctrl+A, Ctrl+C to copy, Ctrl+V to paste.)
  3. This line in the code prevents small attachments, such as icons in signatures from being listed. Raise this as needed. This size filters out items smaller than about 5 KB.
    If oAtt.Size > 5200 Then
  4. You'll need to set Word as a Reference in the VBA Editors Tools > References dialog.
  5. Set a reference to Word

More information as well as screenshots are at How to use the VBA Editor

To test this macro, click in Application_Startup and press Run. Open a message that has one or more attachments and click Reply.

Reply and ReplyAll with the Attachment name

Option Explicit
Private WithEvents oExpl As Explorer
Private WithEvents oItem As MailItem
Private bDiscardEvents As Boolean


Private Sub Application_Startup() 
   Set oExpl = Application.ActiveExplorer 
   bDiscardEvents = False     
End Sub

Private Sub oExpl_SelectionChange()
   On Error Resume Next
   Set oItem = oExpl.Selection.Item(1)
End Sub

' Reply
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)

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

If bDiscardEvents Or oItem.Attachments.Count = 0 Then
       Exit Sub
   End If
    
   Cancel = True
   bDiscardEvents = True
strAtt = ""

For Each oAtt In oItem.Attachments
    If oAtt.Size > 5200 Then 
    strAtt = strAtt & "<<" & oAtt.FileName & ">> "
    End If
Next oAtt

   Dim oResponse As MailItem
   Set oResponse = oItem.Reply
   oResponse.Display
    
    Set olInspector = Application.ActiveInspector()
    Set olDocument = olInspector.WordEditor
    Set olSelection = olDocument.Application.Selection

  olSelection.InsertBefore strAtt

   bDiscardEvents = False
Set oItem = Nothing
End Sub

' Reply All
Private Sub oItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)

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

If bDiscardEvents Or oItem.Attachments.Count = 0 Then
       Exit Sub
   End If
    
   Cancel = True
   bDiscardEvents = True

strAtt = ""

For Each oAtt In oItem.Attachments
    If oAtt.Size > 5200 Then
    strAtt = strAtt & "<<" & oAtt.FileName & ">> "
    End If
Next oAtt

   Dim oResponse As MailItem
   Set oResponse = oItem.ReplyAll
   oResponse.Display
    
    Set olInspector = Application.ActiveInspector()
    Set olDocument = olInspector.WordEditor
    Set olSelection = olDocument.Application.Selection

  olSelection.InsertBefore strAtt   
   bDiscardEvents = False
Set oItem = Nothing
    
End Sub

Written by

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.

If the Post Coment button disappears, press your Tab key.