跳到主要内容

在Outlook中撰写电子邮件时,如何将所有附件名称列出到邮件正文中?

作者:晓阳 最后修改时间:2020-10-23

在Outlook中编写电子邮件时,是否有什么好方法可以将所有附件名称插入邮件正文中? 本文,我将讨论如何解决Outlook中的这项工作。

使用VBA代码编写电子邮件时,将所有附件名称列出到邮件正文中

使用简单功能撰写电子邮件时,将所有附件名称列出到邮件正文中


使用VBA代码编写电子邮件时,将所有附件名称列出到邮件正文中

请执行以下步骤来完成此任务:

1。 按住 ALT + F11 键打开 Microsoft Visual Basic应用程序 窗口。

2。 在 Microsoft Visual Basic应用程序 窗口,双击 本次展望会议 来自 Project1(VbaProject.OTM) 窗格以打开模式,然后将以下代码复制并粘贴到空白模块中。

VBA代码:在邮件正文中列出所有附件名称:

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。 然后继续点击 插页 > 模块,将以下代码复制并粘贴到打开的空白模块中,请参见屏幕截图:

VBA代码:在邮件正文中列出所有附件名称:

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。 然后点击 工具 > 参考资料 ,在 Microsoft Visual Basic应用程序 窗口,弹出 参考-Project1 对话框,检查 Microsoft Word对象库 选项从 可用参考 列表框,请参见屏幕截图:

5。 点击 OK 要退出对话框,则应将宏按钮添加到 快速访问工具栏。 在新 留言 窗口,选择 更多命令 来自 自定义快速访问工具栏 下拉菜单,请参见屏幕截图:

6。 在 Outlook选项 对话框中,进行以下操作:

(1.)选择 来自 从中选择命令 下拉列表;

(2.)单击您刚才插入的宏名称;

(3.)然后单击 添加 按钮将宏添加到 自定义快速访问工具栏.

7。 然后点击 OK 关闭对话框,现在,宏按钮已插入到 快速访问工具栏,请参见屏幕截图:

8。 现在,当您创建新消息并单击宏按钮时,附件名称将被插入到消息正文上方,如以下屏幕截图所示:


使用简单功能撰写电子邮件时,将所有附件名称列出到邮件正文中

如果您有上述代码,可能对您来说很难应用 Kutools for Outlook,其 复制名称 功能,您可以快速复制邮件的附件名称并将其粘贴到所需的任何位置。

请注意:申请这个 复制名称,首先,您应该下载 Kutools for Outlook,然后快速轻松地应用该功能。

安装后 Kutools for Outlook,请这样做:

1。 首先,请创建所需的新电子邮件,然后单击 库工具 > 复制名称 在新的 留言 窗口,请参见屏幕截图:

2。 然后,将弹出一个提示框,提醒您附件名称已复制到剪贴板,请参见屏幕截图:

3。 现在,您只需要按 按Ctrl + V 键将附件名称粘贴到所需的邮件正文中,请参见屏幕截图:


更多相关文章:

  • 在Outlook中使用原始附件全部答复
  • 通常,当您应用“全部答复”功能以将邮件答复给Outlook中的所有收件人时,原始附件将自动丢失。 在Outlook中回复所有人时是否可以附加原始附件?
  • 将附件从Outlook下载/保存到特定文件夹
  • 通常,您可以通过单击Outlook中的附件>保存所有附件来保存一封电子邮件的所有附件。 但是,如果您需要保存所有收到的电子邮件和收到的电子邮件中的所有附件,那么理想吗? 本文将介绍两种解决方案,可以将附件从Outlook自动下载到特定文件夹。
  • 在Outlook中更改默认附件保存位置
  • 您是否对每次启动Outlook时都指定的附件位置感到厌烦? 在本教程中,我们将向您展示如何更改默认附件位置。 此后,即使重新启动Outlook,每次保存附件时,也会自动打开指定的附件保存文件夹。
  • 从Outlook中的电子邮件中删除所有附件
  • 通常,在预览电子邮件时,可以右键单击删除附件,然后选择“删除附件”项。 有时,电子邮件中可能有很多附件,将它们一个一个地删除会很麻烦。 在这里,我们为您安排了两个简单的技巧,以删除一封电子邮件中的所有附件,并在Outlook中也删除多封电子邮件中的所有附件。

最佳办公生产力工具

最新消息:Kutools for Outlook 发布 免费版本!

体验全新的 Kutools for Outlook 免费版本拥有 70 多项令人难以置信的功能,您可以永久使用! 点击立即下载!

🤖 Kutools人工智能 : 具有人工智能魔力的即时专业电子邮件——一键天才回复、完美语气、多语言掌握。轻松改变电子邮件! ...

📧 电子邮件自动化: 自动回复(适用于 POP 和 IMAP)  /  安排发送电子邮件  /  发送电子邮件时按规则自动抄送/密件抄送  /  自动转发(高级规则)   /  自动添加问候语   /  自动将多收件人电子邮件拆分为单独的消息 ...

📨 电子邮件管理: 撤回电子邮件  /  按主题和其他人阻止诈骗电子邮件  /  删除重复的电子邮件  /  高级搜索  /  合并文件夹 ...

📁 附件专业版批量保存  /  批量分离  /  批量压缩  /  自动保存   /  自动分离  /  自动压缩 ...

🌟 界面魔法: 😊更多又漂亮又酷的表情符号   /  收到重要邮件时提醒您  /  最小化 Outlook 而不是关闭 ...

👍 一键奇迹: 使用传入附件回复全部  /   反网络钓鱼电子邮件  /  🕘显示发件人的时区 ...

👩🏼‍🤝‍👩🏻 通讯录和日历: 从选定的电子邮件中批量添加联系人  /  将联系人组拆分为各个组  /  删除生日提醒 ...

只需单击一下即可立即解锁 Kutools for Outlook -永久免费. 别等了, 立即下载并提高您的效率!

kutools for outlook 功能1 kutools for outlook 功能2
 

 

 

Comments (12)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Why am I getting "user-defined type not defined" when I get to Step 8?
This comment was minimized by the moderator on the site
Why am I getting "user-defined type not defined" when I get to Step 8?
This comment was minimized by the moderator on the site
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?
This comment was minimized by the moderator on the site
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!
This comment was minimized by the moderator on the site
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!!
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
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?
This comment was minimized by the moderator on the site
I also don't know how to fix it. Anyone could hep on that?
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
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!
This comment was minimized by the moderator on the site
this is great. Is there any way to merge this with VMS's request above to exclude some specific files included in signatures (.png, .jpg, etc.)?
This comment was minimized by the moderator on the site
Great, thanks for that. I wonder if it is possible that the list of attachments is only attached when I write to a specific email address?
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations