Excel - VBA macro code to pull outlook files by spesific date range in spesific folder and save as today date
Hi everyone,
Need advise from the expert here. I am trying to pull outlook files but the results it extract all the file in that spesific folder.
I am trying to only pull all the files on today date. May i know what code should i put so that the VBA code can only pull the files spesific date or only for today date. And need the file with current date format. Example :- The original file is XXP_Oracle_RPT and save as Oracle Report_20240702.
I hope my question are well explained.
Below are the code :-
Option Explicit
Public Const sOutFolder As String = "C:\Users\harunsitihaj\Documents\Siti (Local)\2. FGReconFix\OracleRPT"
Sub Export_Email()
Dim oApp As Object
Dim oName As Object
Dim oFolder As Object
Set oApp = CreateObject("Outlook.Application")
Set oName = oApp.GetNamespace("MAPI")
Set oFolder = oName.GetDefaultFolder(6).folders("OracleReport")
Dim oMail As Object
Dim OAttach As Object
Dim sAttachName As String
For Each oMail In oFolder.Items
For Each OAttach In oMail.Attachments
sAttachName = OAttach.Filename
sAttachName = sOutFolder & "" & sAttachName
OAttach.SaveAsFile sAttachName
Next OAttach
Next oMail
End Sub