跳至主要内容

如何在Outlook中仅保存特定(Excel)附件?

Author: Siluvia Last Modified: 2025-05-08

Outlook 提供了“保存所有附件”功能,可帮助您一次性将电子邮件中的所有附件保存到特定文件夹。但是,如果您只想保存一个或多个电子邮件中某些类型的附件,例如 Excel 工作簿、Word 文档等,该如何实现呢?本教程为您提供两种解决此问题的方法。

使用 VBA 代码在 Outlook 中仅保存特定文件格式的附件
使用出色的工具轻松在 Outlook 中仅保存特定文件格式的附件


使用 VBA 代码在 Outlook 中仅保存特定文件格式的附件

以下 VBA 代码可以帮助将一个或多个选定电子邮件中仅特定文件格式的附件保存到指定文件夹。请按照以下步骤操作。

1. 启动您的 Outlook。在邮件列表中,选择一个或多个您想从中保存特定文件格式附件的电子邮件。

2. 按 “Alt” + “F11” 打开“Microsoft Visual Basic for Applications”窗口。在打开的窗口中,点击“插入” > “模块”,然后将以下 VBA 代码复制到模块窗口中。

VBA 代码:将电子邮件或多个电子邮件中的特定附件保存到文件夹

Public Sub SaveSpecifyAttachments()
'Updated by ExtendOffice 20210617
Dim xItem As Object, xFldObj As Object
Dim xSelection As Selection
Dim xAttachment As Outlook.Attachment
Dim xSaveFolder As String
Dim xFSO As Scripting.FileSystemObject
Dim xFilePath, xFilesSavePath As String
Dim xExtStr As String, xExt As String
Dim xExtArr() As String, xS As Variant
On Error Resume Next
Set xFldObj = CreateObject("Shell.Application").BrowseforFolder(0, "Select a Folder", 0, 16)
Set xFSO = New Scripting.FileSystemObject
If xFldObj Is Nothing Then Exit Sub
xSaveFolder = xFldObj.Items.Item.Path & "\"
Set xSelection = Outlook.Application.ActiveExplorer.Selection
xExtStr = InputBox("Attachment Format:" + VBA.vbCrLf + "(Please separate multiple file extensions by comma.. Such as: .docx,.xlsx)", "Kutools for Outlook", xExtStr)
If Len(Trim(xExtStr)) = 0 Then Exit Sub
For Each xItem In xSelection
    If xItem.Class = olMail Then
        xFilesSavePath = ""
        For Each xAttachment In xItem.Attachments
            xFilePath = xSaveFolder & xAttachment.FileName
            xExt = "." & xFSO.GetExtensionName(xFilePath)
            xExtArr = VBA.Split(xExtStr, ",")
            xS = VBA.Filter(xExtArr, xExt)
            If UBound(xS) > -1 Then
                xAttachment.SaveAsFile xFilePath
                If xItem.BodyFormat <> olFormatHTML Then
                    xFilesSavePath = xFilesSavePath & vbCrLf & "<file://" & xFilePath & ">"
                Else
                    xFilesSavePath = xFilesSavePath & "" & "" & xFilePath & ""
                End If
            End If
        Next
        xItem.Save
    End If
Next
Set xFSO = Nothing
End Sub

3. 点击“工具” > “引用”;在“引用 - 项目”对话框中,勾选“Microsoft Scripting Runtime”复选框并点击“确定”按钮。

steps on saving only Specific (Excel) Attachment In Outlook using vba

4. 按下“F5”键运行代码。在弹出的“浏览文件夹”对话框中,选择一个文件夹来保存附件。

steps on saving only Specific (Excel) Attachment In Outlook using vba

5. 然后,点击“确定”,在接下来的“Kutools for Outlook”对话框中,输入要保存的附件的文件扩展名并点击“确定”。

注意:对于多个文件扩展名,需要用逗号分隔。

steps on saving only Specific (Excel) Attachment In Outlook using vba

然后,只有指定的附件会被保存。


使用出色的工具轻松在 Outlook 中仅保存特定文件格式的附件

如果您不熟悉 VBA,这里我们推荐您使用“Kutools for Outlook”的“保存所有附件”功能。通过此功能,您可以轻松在 Outlook 中仅保存特定文件格式的附件。

 👉 Kutools for Outlook 现在有了免费版本,其中 70+ 项功能终身免费。立即下载免费版本

1. 选择您想从中保存特定文件格式附件的电子邮件。

2. 点击“Kutools” > “附件工具” > “保存所有”。

steps on saving only Specific (Excel) Attachment In Outlook using kutools for outlook

3. 在“保存设置”对话框中,您需要进行如下配置。

3.1) 在“保存附件到此文件夹”部分,点击 steps on saving only Specific (Excel) Attachment In Outlook using kutools for outlook 按钮以选择一个文件夹来保存附件;
3.2) 点击“高级选项”按钮以展开对话框;
3.3) 在“过滤条件”部分,勾选“附件类型”复选框,然后在文本框中输入要保存的附件的文件扩展名。
提示:对于多个文件扩展名,需要用分号分隔。
3.4) 点击“确定”按钮。见截图:
steps on saving only Specific (Excel) Attachment In Outlook using kutools for outlook

4. 弹出一个对话框提醒您是否要保存附件,点击“确定”继续。

5. 然后另一个对话框弹出,告诉您已保存了多少附件,点击“确定”按钮。

steps on saving only Specific (Excel) Attachment In Outlook using kutools for outlook

现在,只有特定文件格式的附件被保存。


相关文章: