I want to export outlook NON-HTML Email Body into excel with a click of a button inside excel. Below are my codes. Appreciate if anyone could assist me on this.
This is the code that I use to print the plain text email body but I get a lot of unwanted text
sText = StrConv(OutlookMail.RTFBody, vbUnicode)
Range("D3").Offset(i, 0).Value = sText
I did tried this but it prompts run-time error '1004' Application-defined or object-defined error It works on body with HTML tags though.
Range("D3").Offset(i, 0).Value = OutlookMail.Body
This is the structure of my email folders
Below are my complete vba codes
Sub extract_email()
Dim OutlookApp As New Outlook.Application
Dim Folder As Outlook.MAPIFolder
Dim OutlookMail As MailItem
Dim sText As String
Dim i As Integer
Set myAccount = OutlookApp.GetNamespace("MAPI")
Set Folder = myAccount.GetDefaultFolder(olFolderInbox).Parent
Set Folder = Folder.Folders("Test_Main").Folders("Test_Sub")
i = 1
Range("A4:D20").Clear
For Each OutlookMail In Folder.Items
If OutlookMail.ReceivedTime >= Range("B1").Value And OutlookMail.SenderName = "Test_Admin" Then
Range("A3").Offset(i, 0).Value = OutlookMail.Subject
Range("A3").Offset(i, 0).Columns.AutoFit
Range("A3").Offset(i, 0).VerticalAlignment = xlTop
Range("B3").Offset(i, 0).Value = OutlookMail.ReceivedTime
Range("B3").Offset(i, 0).Columns.AutoFit
Range("B3").Offset(i, 0).VerticalAlignment = xlTop
Range("C3").Offset(i, 0).Value = OutlookMail.SenderName
Range("C3").Offset(i, 0).Columns.AutoFit
sText = StrConv(OutlookMail.RTFBody, vbUnicode)
Range("D3").Offset(i, 0).Value = sText
Range("D3").Offset(i, 0).Columns.AutoFit
Range("D3").Offset(i, 0).VerticalAlignment = xlTop
i = i + 1
End If
Next OutlookMail
Set Folder = Nothing
End Sub
OutlookMail.Body
? – PatricK