Outlook收件箱规则获取附件的文件名而不实际下载附件

时间:2018-04-25 11:36:28

标签: vba outlook attachment rule

我正在尝试设置传入规则以获取附件的文件名并自动将其写入Excel,而无需自行下载附件。无论如何在Outlook VBA中使用POP3或IMAP执行此操作吗?

2 个答案:

答案 0 :(得分:0)

如下:

Dim Item As Outlook.MailItem
Item.Attachements(1).FileName

https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/attachment-filename-property-outlook

答案 1 :(得分:0)

尝试以下代码..它可以帮助您浏览收件箱文件夹并获取每个附件文件名..

Sub test()
    Dim a As Attachments
    Dim myitem As Folder
    Dim myItemI As Object
    Dim j As Long
    Dim i As Integer

    ' Your Inbox folder
    Set myitem = Session.GetDefaultFolder(olFolderInbox)

    ' Loop through all mails in Inbox Folder
    For i = 1 To myitem.Items.Count
        'Get the mail number i
        Set myItemI = myitem.Items(i)
        'Get the attachments of the mail number i
        Set a = myItemI.Attachments
        ' if the mail contains attachments
        If Not a Is Nothing Then
            'Go through and display each attachment filename
            For j = 1 To myItemI.Attachments.Count
              MsgBox myItemI.Attachments.Item(j).DisplayName
            Next j
        End If
    Next i

End Sub