How to list all attachment names into message body when composing email in Outlook?

Are there any good ways for us to insert all attachment names into message body when composing an email in Outlook? This article, I will talk about how to solve this job in Outlook.

List all attachment names into message body when composing email with VBA code

List all attachment names into message body when composing email with a simple feature


List all attachment names into message body when composing email with VBA code

Please do with the following steps to finish this task:

1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, double click ThisOutlookSession from the Project1(VbaProject.OTM) pane to open the mode, and then copy and paste the following code into the blank module.

VBA code: List all attachment names into message body:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim xMailItem As MailItem
    If Item.Class = olMail Then
        Set xMailItem = Item
        If xMailItem.Attachments.Count > 0 Then
          AddAttachmentNamesToBody
        End If
    End If
    End Sub

3. Then go on clicking Insert > Module, copy and paste below code into the opened blank module, see screenshot:

VBA code: List all attachment names into message body:

Public Sub AddAttachmentNamesToBody()
    Dim xMailItem As MailItem
    Dim xAttachment As Attachment
    Dim xFileName As String
   Dim xInspector As Outlook.Inspector
    Dim xDoc As Word.Document
    Dim xWdSelection As Word.Selection
    On Error Resume Next
    Set xMailItem = Outlook.ActiveInspector.CurrentItem
    If xMailItem.Attachments.Count = 0 Then
        Exit Sub
    End If
    xFileName = ""
    For Each xAttachment In xMailItem.Attachments
        If xFileName = "" Then
            xFileName = " <" & xAttachment.FileName & "> "
        Else
            xFileName = xFileName & vbCrLf & " <" & xAttachment.FileName & "> "
        End If
    Next xAttachment
    Set xInspector = Outlook.Application.ActiveInspector()
    Set xDoc = xInspector.WordEditor
    Set xWdSelection = xDoc.Application.Selection
    xWdSelection.HomeKey Unit:=wdStory
    xWdSelection.InsertBefore "Attachments: " & vbCrLf & xFileName & vbCrLf & vbCrLf
    Set xMailItem = Nothing
    End Sub

4. And then click Tools > References in the Microsoft Visual Basic for Applications window, in the popped out References-Project1 dialog box, check Microsoft Word Object Library option from the Available References list box, see screenshot:

5. Click OK to exit the dialog box, then you should add the macro button into the Quick Access Toolbar. In the new Message window, choose More Commands from the Customize Quick Access Toolbar drop down, see screenshot:

6. In the Outlook Options dialog box, do the following operations:

(1.) Select Macros from the Choose commands from drop down list;

(2.) Click the macro name that you have inserted just now;

(3.) And then click Add button to add the macro into the Customize Quick Access Toolbar.

7. Then click OK to close the dialog box, now, the macro button has been inserted into the Quick Access Toolbar, see screenshot:

8. Now, when you create new message, and click the macro button, the attachment names will be inserted above the message body as following screenshot shown:


List all attachment names into message body when composing email with a simple feature

May be the above code is soemwhat difficult for you to apply, if you have Kutools for Outlook, with its Copy Names feature, you can quickly copy the attachment names of a message and paste them anywhere you need.

Note:To apply this Copy Names, firstly, you should download the Kutools for Outlook, and then apply the feature quickly and easily.

After installing Kutools for Outlook, please do as this:

1. First, please create the new email you need, and then click Kutools > Copy Names in the new Message window, see screenshot:

2. And then, a prompt box will pop out to remind you the attachment names have been copied to the clipboard, see screenshot:

3. Now, you just need to press Ctrl + V keys together to paste the attachment names to the message body you need, see screenshot:


More relative articles:

  • Reply All With Original Attachments In Outlook
  • Normally, when you apply the Reply All function to reply the message to all recipients in Outlook, the original attachments will be lost automatically. Is it possible to attach original attachments when reply to all in Outlook?
  • Download/Save Attachments From Outlook To A Certain Folder
  • Generally speaking, you can save all attachments of one email with clicking Attachments > Save All Attachments in Outlook. But, if you need to save all attachments from all received emails and receiving emails, any ideal? This article will introduce two solutions to automatically download attachments from Outlook to a certain folder.
  • Change Default Attachment Saving Location In Outlook
  • Have you fed up with finding the attachment location you have specified every time when launching Outlook? In this tutorial, we will show you how to change the default attachment location. After that, the specified attachment saving folder will be opened automatically every time you save the attachments even though you restarting the Outlook.
  • Remove All Attachments From Email In Outlook
  • Normally when you are previewing an email, you can delete an attachment with right clicking and select the Remove Attachment item. Sometimes there may be many attachments in an email message, and it will be tedious to remove them one by one. Here we arrange you with two easy tricks to remove all attachments in one email, and remove all attachments from multiple emails as well in Outlook.

Kutools for Outlook - Brings 100 Advanced Features to Outlook, and Make Work Much Easier!

  • Auto CC/BCC by rules when sending email; Auto Forward Multiple Emails by custom; Auto Reply without exchange server, and more automatic features...
  • BCC Warning - show message when you try to reply all if your mail address is in the BCC list; Remind When Missing Attachments, and more remind features...
  • Reply (All) With All Attachments in the mail conversation; Reply Many Emails in seconds; Auto Add Greeting when reply; Add Date into subject...
  • Attachment Tools: Manage All Attachments in All Mails, Auto Detach, Compress All, Rename All, Save All... Quick Report, Count Selected Mails...
  • Powerful Junk Emails by custom; Remove Duplicate Mails and Contacts... Enable you to do smarter, faster and better in Outlook.
shot kutools outlook kutools tab 1180x121
shot kutools outlook kutools plus tab 1180x121
 
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    VMS · 1 months ago
    When I do this, it always put the attachments at the beginning of the message, no matter where my cursor is located. I then have to copy/paste to the bottom of the email. Is there a way to change that?
    • To post as a guest, your comment is unpublished.
      skyyang · 1 months ago
      Hello, VMS,
      If you want to put the attachments at the the position of your cursor, please replace the second code with following code:

      Public Sub AddAttachmentNamesToBody()
      Dim xMailItem As MailItem
      Dim xAttachment As Attachment
      Dim xFileName As String
      Dim xInspector As Outlook.Inspector
      Dim xDoc As Word.Document
      Dim xWdSelection As Word.Selection
      On Error Resume Next
      Set xMailItem = Outlook.ActiveInspector.CurrentItem
      If xMailItem.Attachments.Count = 0 Then
      Exit Sub
      End If
      xFileName = ""
      For Each xAttachment In xMailItem.Attachments
      If xFileName = "" Then
      xFileName = " <" & xAttachment.FileName & "> "
      Else
      xFileName = xFileName & vbCrLf & " <" & xAttachment.FileName & "> "
      End If
      Next xAttachment
      Set xInspector = Outlook.Application.ActiveInspector()
      Set xDoc = xInspector.WordEditor
      Set xWdSelection = xDoc.Application.Selection
      xWdSelection.InsertBefore "Attachments: " & vbCrLf & xFileName & vbCrLf & vbCrLf
      Set xMailItem = Nothing
      End Sub

      Please try, hope it can help you!
      • To post as a guest, your comment is unpublished.
        VMS · 27 days ago
        That worked! Now another favor... How do I exclude certain file types or names? My required company signature contains a PNG file that I would like to exclude.Thank you!!
        • To post as a guest, your comment is unpublished.
          skyyang · 4 days ago
          To exclude some specific files, please apply the below code, please try it.
          Public Sub AddAttachmentNamesToBody()
          Dim xMailItem As MailItem
          Dim xAttachment As Attachment
          Dim xFileName As String
          Dim xInspector As Outlook.Inspector
          Dim xDoc As Word.Document
          Dim xWdSelection As Word.Selection
          Dim xExt As String
          Dim xFound As Boolean
          Dim xExtArr As Variant
          On Error Resume Next
          xExtArr = Array("docx", "exe") 'change the file extension you want to exclude
          Set xMailItem = Outlook.ActiveInspector.CurrentItem
          If xMailItem.Attachments.Count = 0 Then
          Exit Sub
          End If
          xFileName = ""
          For Each xAttachment In xMailItem.Attachments
          xExt = VBA.Mid(xAttachment.FileName, VBA.InStrRev(xAttachment.FileName, ".") + 1)
          xFound = False
          For i = LBound(xExtArr) To UBound(xExtArr)
          If xExt = xExtArr(i) Then
          xFound = True
          Exit For
          End If
          Next
          If xFound = False Then
          If xFileName = "" Then
          xFileName = " <" & xAttachment.FileName & "> "
          Else
          xFileName = xFileName & vbCrLf & " <" & xAttachment.FileName & "> "
          End If
          End If
          Next xAttachment
          Set xInspector = Outlook.Application.ActiveInspector()
          Set xDoc = xInspector.WordEditor
          Set xWdSelection = xDoc.Application.Selection
          xWdSelection.InsertBefore "Attachments: " & vbCrLf & xFileName & vbCrLf & vbCrLf
          Set xMailItem = Nothing
          End Sub
  • To post as a guest, your comment is unpublished.
    mw4 · 1 years ago
    when I tried this code it sends the attachment names in every email that has attachments.
    I want it to only do it when I click the macro.

    How do I amend the code to do just that?
    • To post as a guest, your comment is unpublished.
      kamelion · 3 months ago
      I also don't know how to fix it. Anyone could hep on that?
  • To post as a guest, your comment is unpublished.
    SB · 1 years ago
    This is wonderful -- thank you! Is there also a way to somehow view all the attachment names in an email that has been sent to you from someone else (i.e. received)? For some reason, the file names are not displaying in full unless you hover, which is ridiculous when you regularly have 15 files to sort through.
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello,
      To List all attachment names in an received email, please copy and pase the below VBA code into the ThisOutlookSession module of the Microsoft Visual Basic for Applications window:

      Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
      Dim xEIDArr As Variant, xEID As Variant, xItem As Object
      Dim xAttachment As Attachment
      Dim xFileName As String
      On Error Resume Next
      xEIDArr = Split(EntryIDCollection, ",")
      For Each xEID In xEIDArr
      Set xItem = Session.GetItemFromID(xEID)
      If xItem.Class = olMail Then
      xFileName = ""
      For Each xAttachment In xItem.Attachments
      If IsEmbeddedAttachment(xAttachment) = False Then
      If xFileName = "" Then
      xFileName = " " & "<" & xAttachment.FileName & ">"
      Else
      xFileName = xFileName & "
      " & " " & "<" & xAttachment.FileName & ">"
      End If
      End If
      Next xAttachment
      If xFileName = "" Then Exit Sub
      xFileName = "Attachments: " & "
      " & xFileName & "
      " & "
      "
      xItem.HTMLBody = "" & xFileName & "" & xItem.HTMLBody
      xItem.Save
      End If
      Next
      Set xItem = Nothing
      End Sub

      Function IsEmbeddedAttachment(Attach As Attachment)
      Dim xAttParent As Object
      Dim xCID As String, xID As String
      Dim xHTML As String
      On Error Resume Next
      Set xAttParent = Attach.Parent
      xCID = ""
      xCID = Attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F")
      If xCID <> "" Then
      xHTML = xAttParent.HTMLBody
      xID = "cid:" & xCID
      If InStr(xHTML, xID) > 0 Then
      IsEmbeddedAttachment = True
      Else
      IsEmbeddedAttachment = False
      End If
      End If
      End Function

      After pasting this code, when new emails with attachments arriving in your Outlook, the attachment names will be listed at the top of the message body automatically.
      Please try it, hope it can help you!