跳到主要内容

如何在Outlook中从电子邮件中删除所有附件?

作者:凯莉 最后修改时间:2020-05-29

通常,在预览电子邮件时,可以右键单击删除附件,然后选择 删除附件 项目。 有时,电子邮件中可能有很多附件,将它们一个一个地删除会很麻烦。 在这里,我们为您安排了两个简单的技巧,以删除一封电子邮件中的所有附件,并在Outlook中也删除多封电子邮件中的所有附件。

在Outlook中手动删除一封电子邮件中的所有附件
使用VBA代码从Outlook中的多封电子邮件中删除所有附件
使用Kutools for Outlook轻松删除一封或多封电子邮件中的所有附件


在Outlook中手动删除一封电子邮件中的所有附件

使用以下命令可以轻松删除所选电子邮件中的所有附件。 删除附件 Outlook中的功能。

第1步:选择将在以后删除其附件的电子邮件。

步骤2:单击“阅读窗格”中的附件之一以激活附件工具。

步骤3:点击 选择全部 按钮在 选择 组上 附件 标签。

此步骤将使您能够立即选择此所选电子邮件中的所有附件。

步骤4:点击 删除附件 按钮在 行动 组上 附件 标签。

步骤5:在警告对话框中,点击 删除附件 按钮。

然后,将尽快删除此选定电子邮件中的所有附件。

备注:删除附件功能在Outlook 2010和更高版本中可以正常使用,但在Outlook 2007中则不能。


从Outlook中的多个选定电子邮件中轻松删除所有附件:

随着 分离所有附件 实用程序 Kutools for Excel,您可以轻松地从多个选定的电子邮件中删除所有附件,如下面的演示所示。 (附件将保存到指定的文件夹中) 立即下载并尝试! (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加载项, 30天免费试用.

1.选择带有您要删除的附件的一封或多封电子邮件,然后单击 库工具 > 附件工具全部分离。 看截图:

2.在 分离设置 对话框,请进行以下配置。

  • 2.1点击 浏览 按钮选择一个文件夹来保存所有已删除的附件。
  • 2.2默认情况下, 拆下以下样式的附件 框被选中,请根据需要选择一个选项将附件根据电子邮件保存到不同的文件夹中。
  • 2.3点击 OK 按钮。 看截图:

:
1.如果要将所有附件保存到同一文件夹中,请取消选中 按照以下样式创建子文件夹 框。
2.删除附件后,附件图标将从邮件列表的电子邮件中消失。 您可以检查 附件图标仍保留在电子邮件中 框,以始终保持它。
2.除了删除所选电子邮件中的所有附件外,您只能按特定条件删除附件。 例如,您只想删除大小超过500KB的附件,请单击 高级选项 按钮以扩展条件,然后将其配置为如下所示的屏幕快照。

3。 点击 Premium Partner 按钮在 全部分离 对话框。

4.然后 Kutools for Outlook 将弹出对话框,告诉您删除了多少个附件。 请点击 OK 按钮。 

现在,所有附件都将被立即删除,只有超链接保留在所选电子邮件中。 您可以单击超链接以根据需要打开相应的附件。

  如果您想免费试用(30天)此实用程序, 请点击下载,然后按照上述步骤进行操作。


最佳办公生产力工具

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

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

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

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

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

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

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

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

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

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

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

 

 

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
There are no comments posted here yet
Load More
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations