Export Mail Body with Formatting in Excel Sheet

HaiderAliKhan

New Member
Joined
Mar 27, 2014
Messages
2
Hi Excel Gurus,

I am trying to automate below task: -
User manually selects(searches for email basically) the email in Inbox and click on forward button and then copies the whole body (Ctrl+A) then (Ctrl+C) and pastes (Ctrl+V) in Sheet1 of workbook.

I am successful in referencing an email from Excel VBA to extract Subject, ReceivedTime but not able to extract mail body with HTML formatting. I am able to fetch mailbody with below line of code.

Sheet1.cells(1,1) = olMail.body, but that doesn't help as it copies unformatted text to Sheet1.

I need the body in the same format it gets pasted manually.Please help.

Thanks in advance.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi

Code:
Sub FromClip()
Dim oApp As Outlook.Application, oMapi As Outlook.MAPIFolder    ' Excel module
Dim oMail As Outlook.MailItem, odata As MSForms.DataObject


On Error Resume Next
Set oApp = GetObject(, "Outlook.Application")
If (oApp Is Nothing) Then Set oApp = CreateObject("Outlook.Application")
On Error GoTo 0


Set oMapi = oApp.GetNamespace("MAPI").Folders(1).Folders(1)     ' desired folder
Set oMail = oMapi.Items(oMapi.Items.Count)                      ' desired email
Set odata = New MSForms.DataObject
odata.SetText oMail.HTMLBody
odata.PutInClipboard
ActiveSheet.Paste                                               ' import formatted data
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,372
Messages
6,130,223
Members
449,567
Latest member
ashsweety

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top