Outlook - Copy Outlook email body to Excel

Asked By AlexCS on 11-Jul-12 09:44 AM
Hi everyone,

I have been trying to write a macro in Excel to achieve the following:
- search for an item with a particular subject in the Outlook inbox
(there will always be only one item to match the search criteria since
the items are deleted after being processed)
- open that particular item and copy its body to a designated Excel
spreadsheet
-delete the item

So far, the closest I have come to my objective is with the below code.
My problem is that it ends up pasting the entire body of the email in
one single cell in Excel (it would not accept pasting in a range) and
there is no possibility for me to format the data afterwards.

Please help if you have a minute, I honestly do not know what else to
try.

Many thanks,

Alex

Sub Outlook_Final()

Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.Namespace
Dim Fldr As Outlook.MAPIFolder

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)

For Each Item In Fldr.Items
If InStr(Item.Subject, "MACRO VAX 48634 REPORT")  0 Then
Item.Display
vBody = Item.Body
ActiveWorkbook.Sheets("Sheet1").Range("A1").Value = vBody
Item.Delete
End If
Next Item

End Sub




--
AlexCS


Michael Bednarek replied to AlexCS on 17-Jul-12 02:15 AM
microsoft.public.outlook.program_vba:

[snip]

Where else do you want the macro to paste the email body text?

--
Michael Bednarek, Brisbane                         "ONWARD"