I want to read email from outlook in excel macro i want to add some filter for fetching email like subject from date etc.
Loading
I want to read email from outlook in excel macro i want to add some filter for fetching email like subject from date etc.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Apr 16, 2024, 12:20 AM EDT
Sure, you can use VBA (Visual Basic for Applications) in Excel to interact with Outlook. Here’s a basic example of how you might set up a macro to read emails from Outlook, with filters on the subject and date.
Please replace
"Your Subject"and"Your Date"with your actual filter criteria.Sub ReadEmailsFromOutlook() Dim OutlookApp As Object Dim OutlookNamespace As Object Dim Folder As Object Dim OutlookMail As Object Dim i As Integer Set OutlookApp = CreateObject("Outlook.Application") Set OutlookNamespace = OutlookApp.GetNamespace("MAPI") ' Pick the folder you want to read emails from Set Folder = OutlookNamespace.GetDefaultFolder(6) 'Inbox i = 1 For Each OutlookMail In Folder.Items If OutlookMail.ReceivedTime >= "Your Date" And OutlookMail.Subject = "Your Subject" Then ' Examine or do something with each filtered email ' For example, write some details to the spreadsheet Cells(i, 1).Value = OutlookMail.Subject Cells(i, 2).Value = OutlookMail.ReceivedTime Cells(i, 3).Value = OutlookMail.SenderName Cells(i, 4).Value = OutlookMail.Body i = i + 1 End If Next OutlookMail Set Folder = Nothing Set OutlookNamespace = Nothing Set OutlookApp = Nothing End SubThis script will loop through all emails in your Inbox and if the email’s received time is greater than or equal to your specified date and the subject matches your specified subject, it will write the subject, received time, sender’s name, and body of the email to the Excel sheet.
Please note that you need to enable the Microsoft Outlook Object Library in Tools -> References in the VBA editor.
Remember to replace
"Your Date"and"Your Subject"with your actual filter criteria. The date should be in the formatmm/dd/yyyy.This is a basic example and might need to be adjusted based on your specific needs and environment.
Thanks