Hello Everyone!
I've got to made this vba code which downloads attached files from mails that meet criteria to specified folder:
It works great so far, but it only applies to main folder "Inbox". I've tried about everything in the net to "frankestein" my code but I couln't get it to work.
How would you apply this code to every single folder in Outlook account?
Thank you all,
I've got to made this vba code which downloads attached files from mails that meet criteria to specified folder:
VBA Code:
Public Sub downloadifmatchcriteria()
Dim olNs As Outlook.Namespace
Dim Inbox As Outlook.MAPIFolder
Dim Items As Outlook.Items
Dim Item As Outlook.MailItem
Dim Atmt As Attachment
Dim Filter As String
Dim FilePath As String
Dim AtmtName As String
Dim Subject As String
Dim i As Long
Set olNs = Outlook.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
FilePath = "C:\users\zerlotus\Documents\Closing\"
Filter = "[FlagRequest] = Follow Up"
Set Items = Inbox.Items.Restrict(Filter)
Items.Sort "[ReceivedTime]"
For Each Item In Items
DoEvents
If Item.Class = olMail And InStr(Item.Subject, "[Closing]") > 0 Then
'Item.ClearTaskFlag
'Item.UnRead = False
DoEvents
Item.Save
For Each Atmt In Item.Attachments
AtmtName = FilePath & Atmt.filename
Atmt.SaveAsFile AtmtName
Next
End If
Next
Set Inbox = Nothing
Set Items = Nothing
Set Item = Nothing
Set Atmt = Nothing
Set olNs = Nothing
End Sub
It works great so far, but it only applies to main folder "Inbox". I've tried about everything in the net to "frankestein" my code but I couln't get it to work.
How would you apply this code to every single folder in Outlook account?
Thank you all,