跳到主要內容

在Outlook中撰寫電子郵件時,如何將所有附件名稱列出到郵件正文中?

在Outlook中編寫電子郵件時,是否有什麼好方法可以將所有附件名稱插入郵件正文中? 本文,我將討論如何解決Outlook中的這項工作。

使用VBA代碼編寫電子郵件時,將所有附件名稱列出到郵件正文中

使用簡單功能撰寫電子郵件時,將所有附件名稱列出到郵件正文中


使用VBA代碼編寫電子郵件時,將所有附件名稱列出到郵件正文中

請執行以下步驟來完成此任務:

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 在 Microsoft Visual Basic for Applications 窗口,雙擊 本次展望會議 來自 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 for Applications 窗口,彈出 參考-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 - 超過 100 種強大的功能可增強您的 Outlook

🤖 人工智慧郵件助手: 具備人工智慧魔力的即時專業電子郵件——一鍵天才回覆、完美語調、多語言掌握。輕鬆改變電子郵件! ……

📧 電子郵件自動化: 外出(適用於 POP 和 IMAP)  /  安排發送電子郵件  /  發送電子郵件時按規則自動抄送/密件副本  /  自動轉送(進階規則)   /  自動添加問候語   /  自動將多收件者電子郵件拆分為單獨的訊息 ...

📨 電子郵件管理: 輕鬆回憶電子郵件  /  按主題和其他人阻止詐騙電子郵件  /  刪除重複的電子郵件  /  進階搜索  /  合併資料夾 ...

📁 附件專業版批量保存  /  批量分離  /  批量壓縮  /  自動保存   /  自動分離  /  自動壓縮 ...

🌟 介面魔法: 😊更多又漂亮又酷的表情符號   /  使用選項卡式視圖提高 Outlook 工作效率  /  最小化 Outlook 而不是關閉 ...

👍 一鍵奇蹟: 使用傳入附件回覆全部  /   反網路釣魚電子郵件  /  🕘顯示寄件者的時區 ...

👩🏼‍🤝‍👩🏻 通訊錄和行事曆: 從選定的電子郵件中大量新增聯絡人  /  將聯絡人群組拆分為各組  /  刪除生日提醒 ...

超過 100特點 等待您的探索! 按此處了解更多。

閱讀更多       免費下載      購買
 

 

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
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations