PDA

View Full Version : Excel 2010 Outlook Integration Issue



JohnBell5713
06-15-2017, 07:10 PM
My site has recently upgraded to Office 2010 running on Windows 7 corporate servers with thin client, and with Exchange as the mail server.

Excel VBA referencing Outlook now throws unexpected errors per the below code fragments. I suspect an error in the upgrade, and want to verify that the error is not mine. My workbook has references to both the Office14 and Outlook14 libraries. When executing the below code Outlook is open and an ordinary email item (type IPM.Note) is selected. Both routines throw a error 287 at the indicated lines. Note that equivalent code in Outlook functions as expected.

It is as though the olApp handle is not exposing all Outlook functionality. Any advice on what may be happening here would be greatly appreciated.



Option Explicit
Dim olApp As Outlook.Application
Dim objItem As Object

Sub test1()

Set olApp = GetObject(, "Outlook.Application")
Set objItem = olApp.ActiveExplorer.Selection.Item(1)

'Returns "IPM.Note"
Debug.Print objItem.MessageClass

'The following line raises Err 287 "Application-defined or object-defined error"
objItem.SaveAs "H:\TESTMSG.msg", Outlook.olMSG
End Sub

Sub test2()
Dim olPA As Outlook.PropertyAccessor

Set olApp = GetObject(, "Outlook.Application")
Set objItem = olApp.ActiveExplorer.Selection.Item(1)

'The following line raises Err 287 "Application-defined or object-defined error"
Set olPA = objItemBase.PropertyAccessor
End Sub

mancubus
06-15-2017, 11:25 PM
worked with Office 2013:

change Outlook.olMSG to olMSG (test1)
change objItemBase to objItem (test2)

snb
06-16-2017, 12:18 AM
I would write:


Sub M_snb()
GetObject(, "Outlook.Application").ActiveExplorer.Selection.Item(1).SaveAs "H:\TESTMSG.msg", 3
End Sub

In late binding you should always use parameter constants instead of named parameters. Check the object library with the object browser.