首页 > 解决方案 > Outlook 宏,用于保存来自特定人员/以特定标题开头的邮件的附件

问题描述

我需要编写一个 Outlook 宏来保存具有指定标题开头(例如:“报告..”)或指定发件人的邮件的附件。我还没有在 Outlook VBA 中编程,所以我不知道如何开始。你能帮我吗?

标签: vbaoutlook

解决方案


我相信这会做你想要的。

Sub SetFlagIcon()

Const olFolderInbox = 6

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)

Set colItems = objFolder.Items

For Each objMessage In colItems
If objMessage.SenderEmailAddress = "someone@gmail.com" Then
    intCount = objMessage.Attachments.Count
    If intCount > 0 Then
        For i = 1 To intCount
            objMessage.Attachments.Item(i).SaveAsFile "C:\your_path_here\Desktop\" & _
                objMessage.Attachments.Item(i).FileName
        Next
    End If
End If
Next

End Sub

请参阅下面的链接,了解有关此操作的其他一些想法。

https://www.extendoffice.com/documents/outlook/3747-outlook-auto-download-save-attachments-to-folder.html

https://www.pixelchef.net/content/rule-autosave-attachment-outlook


推荐阅读