2017-01-25 171 views
0

我有下面的代码,在Excel 2007中工作得很好,但在Excel 2013年的Excel 2013的Outlook收件人解析失败

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 

我在做什么是解析从文件夹中的邮件在我的收件箱失败。但是,我需要解决收件人但失败。您看到的代码从子代开始,代码的其余部分遵循解析方法。

返回的错误是:

运行时错误“287”: 应用程序定义或对象定义的错误

错误的帮助确实没有提供任何有用的信息。特别是因为这在Excel 2007中完美工作,但现在在“升级”到Excel 2013后失败。

我试过“[email protected]”和“John Smith”和“John A. Smith”等那些不是真名)但没有任何作用。当我将其复制到仍然安装了Office 2007的笔记本电脑时,代码完美无缺。在一小时内,笔记本电脑自动升级到Office 2013,代码失败。

任何帮助将不胜感激。

+0

Under Tools |参考检查Outlook – niton

+0

您的意思是_remove_支票从一个箱子或_add_支票到一个箱子? Visual Basic应用程序 的Microsoft Excel 15.0对象库 的Microsoft Office 15.0对象库 的Microsoft Outlook 15.0对象库 OLE自动化 OutlookAddin 1.0类型库 :我应该在我的,我有以下引用检查原帖已经声明我没有依次检查每一个,并重试宏观。显然,他们中的一些导致初始失败,所以他们必须留下来。其他人,无论是选中还是未选中,仍然会导致解决失败。 谢谢。 – JohnHolliday

回答

2

请尝试等待以查看是否存在延迟响应。

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

谢谢你和一个好主意,但它没有奏效。我将** maxTries **增加到20000,然后增加到200,000,但仍然失败。我怀疑这可能与我不知道的安全设置有关。我不是当地的管理员,尽管我不知道为什么这很重要。我的Outlook和服务器团队目前还没有提供协助。非常感谢你的建议。 – JohnHolliday