Skip to content
DnsLister Forum

Where domain hunters compare notes

[Outlook] Extract Attachments w Unique Names

tldr: Cannot seem to get "extract xlsx from email" to work on one of my two scripts.

I have already tried scouring google/reddit for answers but the solutions do not seem to be working.

Background: I have a successful script running for a different email containing an attachment that has the same name daily, but the same script (duh) cannot be used for extracting an attachment from emails that have a name that changes daily (ie the current date).

I am hoping for a variety of answers that can include (but is not limited to):
– forward the email to myself …?
– extract based on specific folder containing ONLY those emails
– fix the code i have below (because maybe I didn't do it quite right)
– a script that can identify the file name based on yesterday's date (t-1)
– Use Task Scheduler (in some fashion)

Below is the most recent script that i have tried to no avail.

Public Sub SaveABC123ReportAttachments(Item As Outlook.MailItem) Dim olApp As Outlook.Application Dim olNS As Outlook.NameSpace Dim olFolder As Outlook.MAPIFolder Dim mail As Outlook.MailItem Dim recip As Outlook.Recipient Dim targetGroup As String targetGroup = "ABC123@domain.com" Dim att As Outlook.Attachment Dim savePath As String savePath = "C:\Users\Me\...\ThisFolderIsWhereTheyGo" Set olApp = Outlook.Application Set olNS = olApp.GetNamespace("MAPI") Set olFolder = olNS.GetDefaultFolder(olFolderInbox) For Each mail In olFolder.Items If TypeOf mail Is Outlook.MailItem Then ' Check recipients For Each recip In mail.Recipients If LCase(recip.Address) = LCase(targetGroup) Then ' Extract attachments For Each att In mail.Attachments att.SaveAsFile savePath & att.FileName Next att Exit For ' stop checking recipients End If Next recip End If Next mail End Sub 

Source: r/vba · by /u/gutsyspirit

Leave a Reply

Your email address will not be published. Required fields are marked *