cjmulligan96
New Member
- Joined
- Dec 26, 2019
- Messages
- 3
- Office Version
- 2016
- Platform
- Windows
- 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