【发布时间】:2014-09-13 20:26:56
【问题描述】:
我正在尝试使 Outlook 自动发送电子邮件。我使用的简化代码是:
Dim outlook As Outlook.Application = Nothing
Try
outlook = New Outlook.Application
Catch ex as Exception
MsgBox(ex.Message)
End Try
每当我在打开 Outlook 的 Win8.1 上运行它时,我都会收到错误消息:
8008005 服务器执行失败(来自 HRESULT 的异常:0x8008005 (CO_E_SERVER_EXEC_FAILURE))
研究错误表明原因是因为我打开了 Outlook,它无法创建新实例。所以我修改了我的代码:
Dim outlook As Outlook.Application = Nothing
Try
If Process.GetProcessesByName("OUTLOOK").Length > 0 Then
outlook = Marshal.GetActiveObject("Outlook.Application")
Else
outlook = New Outlook.Application
End If
Catch ex as Exception
MsgBox(ex.Message)
End Try
当我这次运行它时,它会尝试连接到现有进程并出现错误:
操作不可用(HRESULT 异常:0x800401E3 (MK_E_UNAVAILABLE))
所以我既不能创建新实例,也不能连接到现有实例。我不知道该怎么办。
【问题讨论】:
标签: vb.net windows outlook automation