Mike French
asked on
Excel vba finding attachment in Outlook
I have code that runs through and finds an attachment in Outlook. It takes a long time due to the fact that I have a lot of emails in my inbox. The problem is that, for some reason, the search starts with the oldest emails in the inbox. Why is this? Is there a way to make the search begin with the newest emails?
Sub GetAttachmentFromInbox()
Dim ns As Namespace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFold erInbox)
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
If Left(Atmt.FileName, 11) = "JAN_-_Sales" Then
Stop
'FileName = Range("COFolder").Value & "\" & Atmt.FileName
MsgBox FileName
'Atmt.SaveAsFile FileName
Exit Sub
End If
Next Atmt
Next Item
End Sub
Sub GetAttachmentFromInbox()
Dim ns As Namespace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFold
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
If Left(Atmt.FileName, 11) = "JAN_-_Sales" Then
Stop
'FileName = Range("COFolder").Value & "\" & Atmt.FileName
MsgBox FileName
'Atmt.SaveAsFile FileName
Exit Sub
End If
Next Atmt
Next Item
End Sub
Could you not add a restrict to your iteration to limit the items to actually process?
ASKER
How can I restrict it to today's date?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Daniel!!!
I should be able to make this code work!
I should be able to make this code work!