OpenSharedItem引发错误的无效路径或URL

时间:2019-08-13 22:36:45

标签: vba runtime-error outlook-vba

我正在尝试将ics文件导入Outlook2016。在Server 2012 R2上运行。

我从-> https://gallery.technet.microsoft.com/office/Open-the-icsical-file-49e2263c

获得了代码

这是我的代码:

Public Sub OpeniCal()

 'Declaration
 Dim oNamespace As NameSpace
 Dim oSharedItem As AppointmentItem

 ' Get a reference to a NameSpace object.
 Set obNamespace = Application.GetNamespace("MAPI")

 ' Open the iCal file containing the shared item and display it
 Set oSharedItem = obNamespace.OpenSharedItem("C:\temp\ICS\EventCalendar.ics")
 'oSharedItem.Display

 'Save the ical to your Calendar
 oSharedItem.Save

End Sub

到达线路时

Set oSharedItem = obNamespace.OpenSharedItem("C:\temp\ICS\EventCalendar.ics")

我明白了

  

运行时错误'440':无效的路径或URL。

URL /路径有效且文件夹中存在文件。

怎么了?我该如何解决?

编辑: 我尝试将服务器名称放入路径(“ \ ServerName \ temp \ ICS \ EventCalendar.ics”)中,但遇到相同的错误。 Error, Invalid Path

谢谢

S

1 个答案:

答案 0 :(得分:0)

  

运行时错误'440':无效的路径或URL。

首先,确保指定的文件可访问。该错误表示指定的字符串格式错误或文件/文件夹不存在。

  

在Server 2012 R2上运行

不清楚是手动还是以编程方式运行Outlook。

Microsoft当前不建议并且不支持从任何无人参与的非交互客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT Services)自动化Microsoft Office应用程序,因为Office可能表现出不稳定在这种环境中运行Office时的行为和/或死锁。

如果要构建在服务器端上下文中运行的解决方案,则应尝试使用对无人值守执行安全的组件。或者,您应该尝试找到允许至少部分代码在客户端运行的替代方法。如果您从服务器端解决方案中使用Office应用程序,则该应用程序将缺少许多成功运行所需的功能。此外,您将承担整体解决方案稳定性的风险。在Considerations for server-side Automation of Office文章中了解有关此内容的更多信息。

相关问题