我正在尝试创建一个应用程序,允许用户使用 Outlook Interop 在共享 Outlook 日历上为我们的业务创建约会项目(你是这么说的吗?)。
日历位于我的帐户中,我已授予需要它的每个人的权限。这些用户可以创建和修改日历,而不会从他们的真实 Outlook 客户端中产生问题。我已经编写了以下函数,当它在我的帐户登录的情况下运行时运行良好。当我注销并进入其他用户帐户时,它会引发异常。
Public Sub AddAppointment()
Try
Dim Application As Outlook.Application = New Outlook.Application
Dim NS As Outlook.NameSpace = Application.GetNamespace("MAPI")
Dim RootFolder As Outlook.Folder
Dim CalendarFolder As Outlook.Folder
Dim PlumbingCalendarFolder As Outlook.Folder
Dim Appointment As Outlook.AppointmentItem
RootFolder = NS.Folders("[email protected]") 'exception here
CalendarFolder = RootFolder.Folders("Calendar")
FletcherCalendarFolder = CalendarFolder.Folders("Plumbing Tasks")
Appointment = FletcherCalendarFolder.Items.Add("IPM.Appointment")
'with/end with guts that define the appointmentitem here
Appointment.Save()
MessageBox.Show("An event for this due date was added to the calendar.")
Application = Nothing
Catch ex As Exception
MessageBox.Show("The event for this due date could not be added to the calendar. The following error occurred: " & ex.Message)
End Try
End Sub
当我尝试设置 RootFolder 时抛出异常 - 说“尝试的操作失败。找不到对象。当日历所有者登录时它工作的事实让我相信我不明白我应该如何从不同的帐户获取文件夹。我很亲近吗?我知道接收者对象并使用Outlook.Namespace.CreateRecipient
、 以及 来创建并稍后解决它NameSpace.GetShareDefaultFolder
,但是我尝试过的所有组合都以完全相同的方式失败。我觉得我错过了一些愚蠢的东西。
能够让这个工作(FeelsGoodMan)。当我发现Outlook.NameSpace.GetFolderFromID
. EntryID 显然是 Outlook 对象的唯一标识符(?不要引用我。)通过观察哪些文件夹起作用,我能够获得日历的 EntryID,然后通过使用GetFolderFromID
我能够获得一个工作文件夹我的代码。
Public Sub AddAppointment()
Const ENTRYID As String = "IdIGotFromWatch"
Try
Dim Application As Outlook.Application = New Outlook.Application
Dim NS As Outlook.NameSpace = Application.GetNamespace("MAPI")
Dim CalendarFolder As Outlook.Folder
Dim Appointment As Outlook.AppointmentItem
CalendarFolder = NS.GetFolderFromID(ENTRYID)
Appointment = CalendarFolder.Items.Add("IPM.Appointment")
'with/end with guts that define the appointmentitem here
Appointment.Save()
Application = Nothing
Catch ex As Exception
MessageBox.Show("The event for this due date could not be added to the calendar. The following error occurred: " & ex.Message)
End Try
End Sub
编辑:我认为应该说这个解决方案只有在日历/文件夹保持原样并且不移动时才对我有用。如果我理解正确,如果日历被重新定位,EntryID 也会改变。我不确定还有什么会触发 ID 的更改(也许重命名?等),但我不明白为什么我不能只更新 ID 以反映将来的更改。这对我有用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句