Can't import body of email since Office upgrade

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
I have been using a macro to import the body of an Outlook message from Excel, this has worked flawlessly in Officer 2013. I have recently upgraded to Office 2016 and now it won't work.

The routine is able to read Outlook fine, (other parts of the module count how many emails have a certain subject line), but it fails on the line which tries to read the email body. For info, I have checked the Outlook settings and they are identical to what was in 2013.

My code:

VBA Code:
Dim objNS As Outlook.Namespace
Dim objFolder As Outlook.MAPIFolder
Set objNS = GetNamespace("MAPI")
Application.ScreenUpdating = False

Set objFolder = objNS.Folders("DEMAND PROJECT Mailbox").Folders("Inbox")
Set DestFolder = objNS.Folders("DEMAND PROJECT Mailbox").Folders("Emails")

For Each Item In objFolder.Items

If InStr(Item.Subject, "Demand Data") Then
Body = Item.Body

and this is the line that fails:

VBA Code:
Body = Item.Body

Has anyone experienced this and can point me towards a solution?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Works fine for me. What is 'Body' variable declared as? Also, as a general note, it's not a good idea to just loop through all emails. While you can, you shouldn't. Your code will be fairly inefficient. Instead, look at the Restrict method to basically filter the email objects to a collection, then peruse that. Here is more info on Restrict.
 
Upvote 0
Thanks Zack - I've looked at the Restrict method and that does what I need just fine, so problem sorted. Many thanks!
 
Upvote 0

Forum statistics

Threads
1,215,212
Messages
6,123,655
Members
449,113
Latest member
Hochanz

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