我在 Outlook 中有很多带附件的邮件,我只需要删除附件,我该怎么做?我有 10,000 个附件,如何更轻松地完成?
答案1
据我所知,没有选项可以一次删除多个电子邮件的附件,但您可以使用 VBA 来执行此操作。请参考以下步骤:
1.在Documents中创建一个文件夹,并将其命名为“OLAttachments”;
2.按Alt+F11打开VBA 编辑器;
3.扩大项目1>Microsoft Outlook 对象>此 Outlook 会话;
4.在编辑窗格中复制并粘贴以下 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
5.保存代码;
6.在 Outlook 顶部,单击向下箭头>更多命令…;
然后宏就会显示在顶部;
8.选择要删除附件的邮件(按住Ctrl键单击分散的邮件,或按住Shift键选择相邻的邮件)
9.单击宏将显示在顶部,然后电子邮件的附件将被删除到 OLAttachments 文件夹中。
希望以上内容有帮助!
答案2
Outlook 是一个专有数据库。
我还没有看到过可以只删除附件的程序,尽管手动删除很容易。
因此,你的目标实际上是无法实现的。
“轻松”前进的道路:
存档旧邮件(比如所有超过 1 年的邮件)。
档案可以移至备份系统。
现在,根据需要删除当前电子邮件中的附件。
这将发挥良好的作用(我这样做)并减少所需的 Outlook 数据存储空间。