将约会添加到 Outlook 默认约会文件夹和共享文件夹

Adding appointment to outlook default appointment folder as well as shared folder

我想使用 VBA 向用户 outlook 日历添加一个约会,它既显示在执行宏的 outlook 应用程序日历上,也存在于 exchange 上的用户共享文件夹中服务器(以便它显示在用户的智能手机日历等上)。

目前我可以做到either/or:

Set myOlApp = Application
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderCalendar)
Set exchFolder = myNamespace.GetSharedDefaultFolder(myOlApp.Session.CurrentUser, olFolderCalendar)
...

Set myAppointment = myOlApp.CreateItem(olAppointmentItem) 'shows in the executing application calendar
'OR
Set myAppointment = exchFolder.items.add(olAppointmentItem) 'shows in the smartphone calendar
'then set whatever details we want for the appointment
With myAppointment
    .ReminderSet = False
    .AllDayEvent = False
    .Sensitivity = olNormal
    .Subject = "on call"
    .Start = onCall(i).Begin
    .Duration = onCall(i).Duration
    .Save
End With

当然,宏可以遍历并在默认日历文件夹和交换服务器文件夹中创建新约会。然而,如果每个约会都被分配了自己的唯一 ID,这将是一个真正的 hack(也就是说,我们最终得到 2 个代表同一事件的约会,但每个约会都有不同的唯一 ID)。

有没有办法将相同的约会实例添加到 defaultFolder 和 sharedDefaultFolder 的文件夹集合中?如果不是,是否有一种好方法可以确保约会的两个版本都是精确的克隆,具有相同的唯一标识符等?

outlook中的约会项有一个我不知道的CopyTo方法,所以保存后调用这个方法并复制到exchange文件夹似乎解决了我的问题

Set myAppointment = myOlApp.CreateItem(olAppointmentItem)
With myAppointment
    'all the properties we wish to assign here
    .Save
    .CopyTo exchFolder, olCreateAppointment
End With

这个答案最初有 olCopyAsAccept 选项,但后来我发现这将为宏创建的每个约会创建一个已发送邮件项目