1
votes

I have an Excel VBA script that references Outlook objects. This used to run in prior Office versions.

With Office 2016 and I am getting:

Run-time error '287':
Application-defined or object-defined error

Here is part of my code:

Dim olApp As Outlook.Application

Dim olNS As Outlook.Namespace

Dim Rec As Outlook.Recipient

Dim olGAL As Outlook.AddressList

Set olApp = Outlook.Application

Set olNS = olApp.GetNamespace("MAPI")

Set olGAL = olNS.GetGlobalAddressList

Set Rec = olNS.CreateRecipient(Cells(1, 1))

Rec.Resolve

Cells(1,1) contains a valid email address.

The '287' error comes in on Rec.Resolve.

I have Microsoft Office 16.0 Object Library checked in Tools/References.

I checked Trust Center Settings in Outlook under Programmatic Access. There are three radio button choices about suspicious activity handling which are all unchecked. My antivirus status is set to Valid.

2

2 Answers

0
votes

To make sure you are dealing with a valid string (not empty) I'd suggest declaring a string variable:

Dim recipient as String 

Set recipient = Cells(1, 1)

MsgBox recipient

Set Rec = olNS.CreateRecipient(recipient)

Rec.Resolve

Nothing has been changed in the Office or Outlook PIAs. You just needed to replace the Outlook COM referece according to the Outlook version used on a system. The Resolve method remains the same.

0
votes

You never initialize the olApp variable. replace the line

Set olApp = Outlook.Application

with

Set olApp = CreateObject("Outlook.Application")