1

I have the following code that worked fine in Excel 2007 but fails in Excel 2013.

Dim lappOutlook As Outlook.Application
Dim lappNamespace As Outlook.Namespace
Dim lappRecipient As Outlook.RECIPIENT

Set lappOutlook = CreateObject("Outlook.Application")
Set lappNamespace = lappOutlook.GetNamespace("MAPI")
Set lappRecipient = lappNamespace.CreateRecipient("smithj1")

lappRecipient.Resolve

What I'm doing is parsing emails from a folder in my inbox. However, I need to resolve the recipient but that fails. The code you see starts out the sub and the remainder of the code follows the resolve method.

The error returned is:

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

The error help really does not provide any useful information. Especially since this worked perfectly in Excel 2007 but now fails after an "upgrade" to Excel 2013.

I have tried "smithj1@company.org" and "John Smith" and "John A. Smith", etc. (those are not the real name) but nothing works. When I copied this to a laptop that still had Office 2007 on it, the code ran perfectly. Within the hour, the laptop was "upgraded" automatically to Office 2013 and the code failed.

Any help would be greatly appreciated.

  • Under Tools | References check off Outlook – niton Jan 25 '17 at 21:24
  • Do you mean to _remove_ a check from a box or _add_ a check to a box? I should have stated in my original post that I have the following references checked: Visual Basic for Applications Microsoft Excel 15.0 Object Library Microsoft Office 15.0 Object Library Microsoft Outlook 15.0 Object Library OLE Automation OutlookAddin 1.0 Type Library I've unchecked each one in turn and retried the macro. Obviously, some of them cause an initial fail so they have to stay. The others, whether checked or unchecked, still cause the resolve failure. Thanks. – JohnHolliday Jan 30 '17 at 21:32
  • For what it's worth, I am having the same problem in Excel 2016. It used to work fine in what I believe was Excel 2010. One thing I've noticed: When I type in the code: lappRecipient.**Resolve**, it reformats it to lappRecipient.**resolve** (lower case resolve) Not sure if that's significant, but I thought it was odd. – Dennis Hancy May 12 '20 at 13:19

1 Answers1

1

Try waiting to see if there is a delayed response.

Private Sub openOutlook2()

Dim lappOutlook As Outlook.Application
Dim lappNamespace As Outlook.Namespace
Dim lappRecipient As Outlook.Recipient

Dim strAcc As String

Dim maxTries As Long
Dim errCount As Long

Set lappOutlook = CreateObject("Outlook.Application")
Set lappNamespace = lappOutlook.GetNamespace("MAPI")

strAcc = "smithj1"
Set lappRecipient = lappNamespace.CreateRecipient(strAcc)

maxTries = 2000

On Error GoTo errorResume

Retry:

    DoEvents

    ' For testing error logic. No error with my Excel 2013 Outlook 2013 setup.
    ' Should normally be commented out
    'Err.Raise 287

    lappRecipient.Resolve

On Error GoTo 0

If lappRecipient.Resolved Then
     Debug.Print strAcc & " resolved."
     MsgBox strAcc & "  resolved."
Else
    Debug.Print strAcc & " not resolved."
    MsgBox "No error: " & strAcc & " not resolved."
End If

ExitRoutine:

    Set lappOutlook = Nothing
    Set lappNamespace = Nothing
    Set lappRecipient = Nothing

    Debug.Print "Done."

    Exit Sub

errorResume:

    errCount = errCount + 1

    ' Try until Outlook responds
    If errCount > maxTries Then

        ' Check if Outlook is there and Resolve is the issue
        lappNamespace.GetDefaultFolder(olFolderInbox).Display
        GoTo ExitRoutine

    End If

    Debug.Print errCount & " - " & Err.Number & ": " & Err.Description
    Resume Retry

End Sub
niton
  • 8,771
  • 21
  • 32
  • 52
  • Thank you and a great idea, but it didn't work. I increased **maxTries** to 20,000 then to 200,000 and it still failed. I suspect this may have something to do with a security setting I am not privy to. I am not a local administrator though I don't know why that would matter. And my Outlook and server teams are currently not forthcoming with assistance. Thank you very much for the suggestion. – JohnHolliday Feb 02 '17 at 18:16