跳到主要內容

如何在Outlook中從電子郵件中刪除所有附件?

通常,在預覽電子郵件時,可以右鍵單擊刪除附件,然後選擇 刪除附件 項目。 有時,電子郵件中可能有很多附件,將它們一個個地刪除會很麻煩。 在這裡,我們為您安排了兩個簡單的技巧,以刪除一封電子郵件中的所有附件,並在Outlook中也刪除多封電子郵件中的所有附件。

在Outlook中的一封電子郵件中手動刪除所有附件
使用VBA代碼從Outlook中的多封電子郵件中刪除所有附件
使用Kutools for Outlook輕鬆刪除一封或多封電子郵件中的所有附件


在Outlook中的一封電子郵件中手動刪除所有附件

使用以下命令可以輕鬆刪除所選電子郵件中的所有附件。 刪除附件 Outlook中的功能。

步驟1:選擇要在以後刪除附件的電子郵件。

步驟2:單擊“閱讀窗格”中的附件之一以激活附件工具。

步驟3:點擊 選擇全部 按鈕在 選擇 組上 附件 標籤。

此步驟將使您能夠立即選擇此所選電子郵件中的所有附件。

步驟4:點擊 刪除附件 按鈕在 動態 組上 附件 標籤。

步驟5:在警告對話框中,點擊 刪除附件 按鈕。

然後,將盡快刪除此選定電子郵件中的所有附件。

備註:刪除附件功能在Outlook 2010和更高版本中可以正常使用,但在Outlook 2007中則不能。


從Outlook中的多個選定電子郵件中輕鬆刪除所有附件:

隨著 分離所有附件 的效用 Excel的Kutools,您可以輕鬆地從多個選定的電子郵件中刪除所有附件,如下面的演示所示。 (附件將保存到指定的文件夾中) 立即下載並嘗試! (30 天免費試用)


使用VBA代碼從Outlook中的多封電子郵件中刪除所有附件

如果要從Microsoft Outlook中的多封電子郵件中刪除所有附件,則以下方法將幫助您輕鬆地進行操作。 我們推薦你 啟用Microsoft Outlook中的所有宏 首先。

步驟1:前往的資料夾 我的文檔,創建一個新文件夾,並將其命名為 OLA附件

步驟2:選擇多封電子郵件,您將在以後刪除其附件。

注意: 您可以選擇不連續的電子郵件,同時按住 按Ctrl 鍵並單擊。

您可以選擇連續的電子郵件,同時按住 轉移 鍵並單擊。

步驟3:按,打開VBA編輯器 其他 關鍵和 F11 關鍵在同一時間。

步驟4:展開 Project1 > Microsoft Outlook對象 在左欄中,然後雙擊 本次展望會議 在編輯器中打開它。 請參閱以下屏幕截圖:

步驟5:將以下VBA代碼複製並粘貼到編輯窗格中。

Public Sub ReplaceAttachmentsToLink()
Dim objApp As Outlook.Application
Dim aMail As Outlook.MailItem 'Object
Dim oAttachments As Outlook.Attachments
Dim oSelection As Outlook.Selection
Dim i As Long
Dim iCount As Long
Dim sFile As String
Dim sFolderPath As String
Dim sDeletedFiles As String
 
    ' Get the path to your My Documents folder
    sFolderPath = CreateObject("WScript.Shell").SpecialFolders(16)
    On Error Resume Next
 
    ' Instantiate an Outlook Application object.
    Set objApp = CreateObject("Outlook.Application")
 
    ' Get the collection of selected objects.
    Set oSelection = objApp.ActiveExplorer.Selection
 
    ' Set the Attachment folder.
    sFolderPath = sFolderPath & "\OLAttachments"
 
    
    ' Check each selected item for attachments. If attachments exist,
    ' save them to the Temp folder and strip them from the item.
    For Each aMail In oSelection
 
    ' This code only strips attachments from mail items.
    ' If aMail.class=olMail Then
    ' Get the Attachments collection of the item.
    Set oAttachments = aMail.Attachments
    iCount = oAttachments.Count
     
       
    If iCount > 0 Then
     
        ' We need to use a count down loop for removing items
        ' from a collection. Otherwise, the loop counter gets
        ' confused and only every other item is removed.
         
        For i = iCount To 1 Step -1
         
            ' Save attachment before deleting from item.
            ' Get the file name.
            sFile = oAttachments.Item(i).FileName
             
            ' Combine with the path to the Temp folder.
            sFile = sFolderPath & "\" & sFile
             
            ' Save the attachment as a file.
            oAttachments.Item(i).SaveAsFile sFile
             
            ' Delete the attachment.
            oAttachments.Item(i).Delete
             
            'write the save as path to a string to add to the message
            'check for html and use html tags in link
            If aMail.BodyFormat <> olFormatHTML Then
                sDeletedFiles = sDeletedFiles & vbCrLf & "<file://" & sFile & ">"
            Else
                sDeletedFiles = sDeletedFiles & "<br>" & "<a href='file://" & _
                sFile & "'>" & sFile & "</a>"
            End If
             
                         
        Next i
        'End If
             
       ' Adds the filename string to the message body and save it
       ' Check for HTML body
       If aMail.BodyFormat <> olFormatHTML Then
           aMail.Body = aMail.Body & vbCrLf & _
           "The file(s) were saved to " & sDeletedFiles
       Else
           aMail.HTMLBody = aMail.HTMLBody & "<p>" & _
           "The file(s) were saved to " & sDeletedFiles & "</p>"
       End If
       
       aMail.Save
       'sets the attachment path to nothing before it moves on to the next message.
       sDeletedFiles = ""
    
       End If
    Next 'end aMail
     
ExitSub:
 
Set oAttachments = Nothing
Set aMail = Nothing
Set oSelection = Nothing
Set objApp = Nothing
End Sub

步驟6:按 F5 運行此VBA代碼。

現在,將刪除所選電子郵件中的所有附件,並在所有所選電子郵件的底部保留指向每個已刪除附件的超鏈接。


使用Kutools for Outlook輕鬆刪除一封或多封電子郵件中的所有附件

全部分離 的附件實用程序 Kutools for Outlook 可以快速刪除Outlook中一封或多封選定電子郵件中的所有附件。 請執行以下操作。

Kutools for Outlook :擁有100多個方便的Outlook加載項, 60天免費試用.

1.選擇一個或多個帶有您要刪除的附件的電子郵件,然後單擊 庫工具 > 附件工具全部分離。 看截圖:

2。 在裡面 分離設置 對話框,請進行以下配置。

  • 2.1點擊 瀏覽 按鈕選擇一個文件夾來保存所有已刪除的附件。
  • 2.2默認情況下, 拆下以下樣式的附件 框被選中,請根據需要選擇一個選項將附件根據電子郵件保存到不同的文件夾中。
  • 2.3點擊 OK 按鈕。 看截圖:

筆記:
1.如果要將所有附件保存到同一文件夾中,請取消選中 按照以下樣式創建子文件夾 框。
2.刪除附件後,附件圖標將從郵件列表的電子郵件中消失。 您可以檢查 附件圖標仍保留在電子郵件中 框,以始終保持它。
2.除了刪除選定電子郵件中的所有附件外,您只能按特定條件刪除附件。 例如,您只想刪除大小超過500KB的附件,請單擊 高級選項 按鈕以擴展條件,然後將其配置為如下所示的屏幕快照。

3。 點擊 按鈕在 全部分離 對話框。

4.然後 Kutools for Outlook 將彈出對話框,告訴您刪除了多少個附件。 請點擊 OK 按鈕。 

現在,所有附件都將被立即刪除,只有超鏈接保留在所選電子郵件中。 您可以單擊超鏈接以根據需要打開相應的附件。

  如果您想免費試用(60天)此實用程序, 請點擊下載,然後按照上述步驟進行操作。


最佳辦公生產力工具

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

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

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

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

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

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

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

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

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

閱讀更多       免費下載      購買
 

 

Comments (33)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello,
MS recently changed the storage limits for Hotmail. Attachments are counted towards storage used.
Many users would like to remove only the attachments in bulk. Your VBA script may be the solution for these users.
Can you confirm if this script still works for Hotmail users in 2023?
Thank you in advance.
This comment was minimized by the moderator on the site
The article and the comments below are very helpful! Thanks!
This comment was minimized by the moderator on the site
 Hello, I use the VBA code, unfortunaltely all the attachements were deleted from the emails, and they were not storage in any of the folders... so i lost many attachment files. anyone knows how can i restored
This comment was minimized by the moderator on the site
The VBA code shown in solution 2 works fine, however, but my goal is to remove only attachments which are not inline the message. Being VBA ignorant I would like to ask if it is possible to modify the code in that manner it would remove only attached files, not pictures inside the email text. It would surely make my day :)

Thank you in advance
This comment was minimized by the moderator on the site
Can somebody change the code so that only for example attachments named "TermsAndConditions.pdf" are deleted
This comment was minimized by the moderator on the site
Dear Rene,
Please follow the steps in the above second method, run the below VBA code. In an opening dialog box, please enter the attachment's name with the file extension (such as test.docx), and then click the OK button to just remove it from the selected email.

Sub ReplaceAttachmentsToLink()
Dim xMail As Outlook.MailItem
Dim xAttachments As Outlook.Attachments
Dim xSelection As Outlook.Selection
Dim i, xCount As Long
Dim xFile, xFldPath, xDelFiles, xFileName As String
Dim xFlag As Boolean

xFldPath = CreateObject("shell.Application").NameSpace(5).self.Path
On Error Resume Next
Set xSelection = Outlook.ActiveExplorer.Selection
xFldPath = xFldPath & "\OLAttachments"
xFlag = False
xFileName = InputBox("Attachment name:", "Kutools for Outlook")

If StrPtr(xFileName) = 0 Then Exit Sub
If xFileName <> "" Then
For Each xMail In xSelection
Set xAttachments = xMail.Attachments
xCount = xAttachments.Count
If xCount > 0 Then
For i = xCount To 1 Step -1
xFile = xAttachments.Item(i).FileName
If xFileName = xFile Then
xFlag = True
xFile = xFldPath & "\" & xFile
xAttachments.Item(i).SaveAsFile xFile
xAttachments.Item(i).Delete
If xMail.BodyFormat <> olFormatHTML Then
xDelFiles = xDelFiles & vbCrLf & ""
Else
xDelFiles = xDelFiles & "
" & "" & xFile & ""
End If
End If
Next i
If xFlag = True Then
If xMail.BodyFormat <> olFormatHTML Then
xMail.Body = xMail.Body & vbCrLf & "The file(s) were saved to " & xDelFiles
Else
xMail.HTMLBody = xMail.HTMLBody & "
" & "The file(s) were saved to " & xDelFiles & "
"
End If
End If
xMail.Save
xDelFiles = ""
End If
Next
If xFlag = False Then
MsgBox "The Attachment does not exist!"
Else
MsgBox "The attachment has been deleted."
End If
Else
MsgBox "Please input a attachment name"
End If
Set xAttachments = Nothing
Set xMail = Nothing
Set xSelection = Nothing
End Sub
This comment was minimized by the moderator on the site
Method 1 doesn't work here, as there's only 1 option under 'Selection': Copy.
This comment was minimized by the moderator on the site
Dear Peter,
Outlook users are reporting that the Select All (attachments) feature in Outlook 2016 is missing.
This comment was minimized by the moderator on the site
The VBA Code solution was great .... worked beautifully
This comment was minimized by the moderator on the site
Compile Error Sub or Function not defined??
This comment was minimized by the moderator on the site
VBA code worked great. Many thanks!
This comment was minimized by the moderator on the site
Hi This was really helpful , but as all attachments were not saved when i tried again it gives a message "the macros in this project are disabled".....tried enabling macros in outlook but no luck, any one can help! Regards Lisa
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations