跳到主要內容

如何從Outlook中的電子郵件中刪除特定類型的附件?

您是否曾經嘗試在Outlook中按文件類型刪除多封選定電子郵件中的附件? 例如,從所選電子郵件中刪除所有docx或png附件文件。 您如何在Outlook中解決這項工作?

使用VBA代碼從電子郵件中刪除特定類型的附件


使用VBA代碼從電子郵件中刪除特定類型的附件

要從選定的電子郵件中刪除特定類型的附件,以下VBA代碼可以幫您一個忙,請這樣做:

1。 在郵件列表中選擇要刪除其特定附件類型的電子郵件。

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

3。 然後,點擊 插入 > 模塊,將以下代碼複製並粘貼到打開的空白模塊中,請參見屏幕截圖:

VBA代碼:從電子郵件中刪除特定類型的附件:

Sub DeleteSpecificTypeOfAttachments()
Dim xSelection As Outlook.Selection
Dim xItem As Object
Dim xMailItem As Outlook.MailItem
Dim xAttachment As Outlook.Attachment
Dim xFileType As String
Dim xType As String
Dim xFSO As Scripting.FileSystemObject
Dim I As Integer
On Error Resume Next
Set xSelection = Outlook.Application.ActiveExplorer.Selection
Set xFSO = New Scripting.FileSystemObject
xType = ""
xType = InputBox("Attachment Type:", "Kutools for Outlook", xType, 8)
If Len(Trim(xType)) = 0 Then Exit Sub
For Each xItem In xSelection
    If xItem.Class = olMail Then
        Set xMailItem = xItem
       If xMailItem.Attachments.Count > 0 Then
            For I = xMailItem.Attachments.Count To 1 Step -1
                Set xAttachment = xMailItem.Attachments.Item(I)
                xFileType = xFSO.GetExtensionName(xAttachment.FileName)
                If InStr(xFileType, Trim(xType)) > 0 Then
                    xAttachment.Delete
                End If
            Next I
            xMailItem.Save
        End If
    End If
Next
Set xMailItem = Nothing
Set xFSO = Nothing
End Sub

4。 然後仍然在 Microsoft Visual Basic for Applications 窗口中,單擊 工具 > 參考參考-Project1 對話框,然後檢查 Microsoft腳本運行時 選項從 可用參考 列錶框,請參見屏幕截圖:

doc按類型1刪除附加

5。 然後點擊 OK 關閉對話框,現在,按 F5 鍵運行此代碼,並彈出一個提示框,請輸入要刪除的附件類型,請參見屏幕截圖:

doc按類型2刪除附加

6。 點擊 OK,並且所有具有您定義的特定類型的附件都被立即刪除,請參見屏幕截圖:

doc按類型3刪除附加


最佳辦公生產力工具

Kutools for Outlook - 超過 100 種強大的功能可增強您的 Outlook

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

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

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

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

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

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

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

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

閱讀更多       免費下載      購買
 

 

Comments (1)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Awesome, I was looking for this exactly. I just made a modification to remove attachments with specific string on the name.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations