简体   繁体   English

Excel 2013 Outlook 收件人解析失败

[英]Excel 2013 Outlook Recipient Resolve fails

I have the following code that worked fine in Excel 2007 but fails in Excel 2013.我有以下代码在 Excel 2007 中运行良好,但在 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.您看到的代码以 sub 开头,其余代码遵循 resolve 方法。

The error returned is:返回的错误是:

Run-time error '287': Application-defined or object-defined error运行时错误“287”:应用程序定义或对象定义错误

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.特别是因为这在 Excel 2007 中运行良好,但现在在“升级”到 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.我试过“smithj1@company.org”和“John Smith”和“John A. Smith”等(那些不是真名)但没有任何效果。 When I copied this to a laptop that still had Office 2007 on it, the code ran perfectly.当我将其复制到仍然装有 Office 2007 的笔记本电脑时,代码运行良好。 Within the hour, the laptop was "upgraded" automatically to Office 2013 and the code failed.一小时内,笔记本电脑自动“升级”到Office 2013,代码失败。

Any help would be greatly appreciated.任何帮助将不胜感激。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM