As the title suggest, I'm trying to export Undelivered emails in Outlook to Excel (sheet1)
I found this code on the web, and I'm having a little difficulty getting it to work
Ideally I would like the data to appear in columns, a separate column for Email address etc
The Emails are in sub-folder of the Inbox called undelivered.Its running to close to the end and stopping at
Next OutlookMail
If someone could look at it, I would appreciate it very much
Thank you for your help
Sub GetFromOutlook4()
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox).Folders("undelivered")
'.Folders("Sales")
i = 1
For Each OutlookMail In Folder.Items
If TypeName(OutlookMail) = "MailItem" Then
If CDate(OutlookMail.ReceivedTime) >= Range("01_01_2019").Value Then
If CDate(OutlookMail.ReceivedTime) <= Range("12_11_2019").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
i = i + 1
End If
Next OutlookMail
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub
Best wishes
Don
I found this code on the web, and I'm having a little difficulty getting it to work
Ideally I would like the data to appear in columns, a separate column for Email address etc
The Emails are in sub-folder of the Inbox called undelivered.Its running to close to the end and stopping at
Next OutlookMail
If someone could look at it, I would appreciate it very much
Thank you for your help
Sub GetFromOutlook4()
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox).Folders("undelivered")
'.Folders("Sales")
i = 1
For Each OutlookMail In Folder.Items
If TypeName(OutlookMail) = "MailItem" Then
If CDate(OutlookMail.ReceivedTime) >= Range("01_01_2019").Value Then
If CDate(OutlookMail.ReceivedTime) <= Range("12_11_2019").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
i = i + 1
End If
Next OutlookMail
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub
Best wishes
Don