I have code that worked well in Excel/Outlook 2003 on XP, I'm now running Windows 7 Excel/Outlook 2010 and receive an error:
Run-time error '287': Application-defined or object-defined error.
My code is based on this answer in: Send an email from Excel 2007 VBA using an Outlook Template & Set Variables
I'm creating my outlook object and mailitem like this:
Dim MyOlApp
Dim MyOlItem
Set MyOlApp = CreateObject("Outlook.Application")
Set MyOlItem = MyOlApp.CreateItemFromTemplate(Range("oftLocation").Value) 'user defined location
The error appears after I reference MyOlItem
, the code is replacing references in the .htmlBody
Amending to .Body
makes no difference, same error shows.
My references in VBA are set to:
- VBA
- Microsoft Excel 14.0 Object Library
- OLE Automation
- Microsoft Office 14.0 Object Library
- Microsoft Forms 2.0 Object Library
- Microsoft Scripting Runtime
As Outlook.Application
andAs Outlook.MailItem
? Also, have you tried defining the location reference for where theRange("oftLocation").Value
is coming from? Trying to determine how the user is defining that location... (I know stupid little things but thought it worth a shot before proceeding) – Chrismas007