Good afternoon all,
Currently, I receive a lot of daily emails in a subfolder. As part of a daily backup file, I would like to save an attachment that was send yesterday (t-1), from an email with a specific subject.
The macro does save the attachment. However, it keeps on running for ages. I am not sure how to kill the macro as soon it saved the attachment from t-1.
So my question: How do I save an attachment from from an email in outlook, with a specific subject and specific time restriction.
I am looking forward to your input. See below code that I made this far.
Regards,
T
Sub SaveAtt()
Dim ns As Namespace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim Att As Attachment
Dim Path As String
Dim Name As String
Dim Vdate As String
Dim i As Integer
Sheets("Summary").Select
Vdate = Format(Range("B3").Value, "m/dd/yyyy h:mm AM/PM") '''''''''''''''''''Range("B3")=workday(today,-1)
Path = ThisWorkbook.Path & "\"
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set PricingInbox = ns.Folders("Price")
Set Pi = PricingInbox.Folders("Inbox")
Set V = PricingInbox.Folders("V")
For Each Item In V.Items
Set objsubject = V.Items.Find("[Subject] = ""Today's File""")
Set objsubject2 = V.Items.Restrict("[lastModificationTime]> Vdate")
If Item.Subject = "x" Then
Set Att = objsubject.Attachments
DateStamp = Item.LastModificationTime
Att(1).FileName
FileName = Path & Att(1).FileName
Att(1).SaveAsFile FileName
End If
Next
i = 0
End Sub
This one has been solved.
Bookmarks