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
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