我有一个引用Outlook对象的Excel VBA脚本。在以前的Office版本中,这通常可以正常运行。今天,我们有了Office 2016,但出现此错误:
运行时错误'287':应用程序定义或对象定义的错误
这是我的代码的一部分:
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)包含有效的电子邮件地址。
“ 287”错误出现在“ Rec.Resolve”上。
[有人知道这是否归因于Office 2016的更改吗?如果是这样,分辨率是多少?
谢谢!
丹尼斯
为了确保您正在处理有效的字符串(不为空),建议您声明一个字符串变量:
Dim recipient as String
Set recipient = Cells(1, 1)
MsgBox recipient
Set Rec = olNS.CreateRecipient(recipient)
Rec.Resolve
[Office或Outlook PIA中没有任何更改。您只需要根据系统上使用的Outlook版本替换Outlook COM参考。 Resolve方法保持不变。
您永远不会初始化olApp
变量。替换行
Set olApp = Outlook.Application
与
Set olApp = CreateObject("Outlook.Application")