Excel - VBA macro code to pull outlook files by spesific date range in spesific folder and save as today date

Raihana 0 Reputation points
2024-07-02T01:57:35.15+00:00

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

Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,982 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,015 questions
Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,731 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.