Is there a way to copy the body of an e-mail into excel sheet using VBA?
I would like to filter my Outlook e-mails by either the subject or e-mail address of the sender. Then I would like to copy the body of the e-mail and paste it into excel sheet. It would be good to filter the e-mail by sender and choose only the latest e-mail.
The e-mail is going to look something like this:
“Here is the latest report from 01.01.2024 – 01.07.2024”
I need to copy the part of the mail with date range which is 01.01.2024 – 01.07.2024 and paste it into a range of cells.
I found this bit of code on stackoverflow, but I don’t understand it very well and it doesn’t solve all my problems. I think that in this code mails are filtered by mail subject?
Dim olApp As Outlook.Application
Dim olNs As Outlook.Namespace
Dim olFldr As Outlook.MAPIFolder
Dim olItms As Outlook.Items
Dim olMail As Variant
Dim i As Long
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set olFldr = olNs.GetDefaultFolder(olFolderInbox)
Set olItms = olFldr.Items
olItms.Sort "Subject"
i = 1
For Each olMail In olItms
If InStr(1, olMail.Subject, "Criteria") > 0 Then
ThisWorkbook.Sheets("Sheet1").Cells(i, 1).Value = olMail.Body
i = i + 1
End If
Next olMail
Set olFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
Magdalena Konopka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.