I want to Save outlook Attachments from mails after Specific date via VBA. But my code is not doing anything. Someone Please tell what wrong am i doing ? I am using Office 365.
I wrote following code but not solving the issue:-
`Option Explicit
Const AttachmentPath As String = "C:\myattachments\"
Sub GetFromOutlook()
Dim OutlookAtch As Object
Dim NewfileName As String
NewfileName = AttachmentPath & Format(Date, "DD-MM-YYYY") & "-"
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer
Dim col As Long
col = 0
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder =OutlookNamespace.GetDefaultFolder(olFolderInbox).Folders("IT").Folders("Compliance").Folders("Inventory")
i = 1
For Each OutlookMail In Folder.Items
If OutlookMail.Attachments.Count > 0 Then
For Each OutlookAtch In OutlookMail.Attachments
If OutlookMail.ReceivedTime >= Range("From_date").Value Then
Range("Email_Subject").Offset(i, 0).Value = OutlookMail.Subject
Range("Email_Date").Offset(i, 0).Value = OutlookMail.ReceivedTime
Range("Email_Sender").Offset(i, 0).Value = OutlookMail.SenderName
Range("Email_Text").Offset(i, 0).Value = OutlookMail.Body
OutlookAtch.SaveAsFile NewfileName & OutlookAtch.Filename
Range("Email_Attch").Offset(i, 0).Value = OutlookAtch
col = col + 1
End If
Next OutlookAtch
col = 0
i = i + 1
End If
Next OutlookMail
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub`