Outlook inbox rule to get attachments' filename without actually downloading the attachments

355 Views Asked by At

I'm trying to set up an incoming rule to get the attachments' filename and write them to excel automatically without having to download the attachments itself. Is there anyway to do this with POP3 or IMAP in Outlook VBA?

2

There are 2 best solutions below

1
Oskar On

How about something like:

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

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

3
LatifaShi On

Try The code below .. It helps you to go through your inbox folder and get every attachment filename ..

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