问题
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?
回答1:
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
回答2:
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
来源:https://stackoverflow.com/questions/50021295/outlook-inbox-rule-to-get-attachments-filename-without-actually-downloading-the