Pull outlook data into EXCEL file

cjmulligan96

New Member
Joined
Dec 26, 2019
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
  2. MacOS
I have a need to evaluate an outlook folder's contents. I found this VBA on the internet; works well, except I cannot get the body of the email to download. I always get Runtime error '287' Application defined or object defined error. When I debug, it always shows the olmail.body line as the offending code. Please help me figure this out; I'm a bit of a newbie to VBA, so be patient with me as I try to understand any response. Code is below:
VBA Code:
Dim n As Long
Sub Launch_Pad()

Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder

Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.PickFolder

n = 2
Cells.ClearContents

Call ProcessFolder(olFolder)

Set olNS = Nothing
Set olFolder = Nothing
Set olApp = Nothing
Set olNS = Nothing
End Sub

'stepping through gets me to select the folder down to here

Sub ProcessFolder(olfdStart As Outlook.MAPIFolder)

Dim olFolder As Outlook.MAPIFolder
Dim olObject As Variant
Dim olMail As Outlook.MailItem

For Each olObject In olfdStart.Items
If TypeName(olObject) = "MailItem" Then
n = n + 1
Set olMail = olObject
'as long as there is no digital signature, these work fine, but I
'cannot get the email body to print

Cells(n, 1) = olMail.Subject
Cells(n, 3) = olMail.ReceivedTime
Cells(n, 4) = olMail.LastModificationTime
Cells(n, 5) = olMail.Categories
Cells(n, 6) = olMail.Body
Cells(n, 7) = olMail.FlagRequest



End If
Next


Set olMail = Nothing
Set olFolder = Nothing
Set olObject = Nothing
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
If you go to Tools > References... Do you have Microsoft Outlook 16.0 Object Library check marked?
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,855
Members
449,096
Latest member
Erald

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