将事件添加到其他用户的 Outlook 日历

Add event to other user's Outlook calendar

我们的电子邮件系统正在更新到 Exchange 365。我有一个数据库正在将日历事件(员工休假)添加到 public 文件夹。

好吧,更新后的 Exchange 不使用 public 文件夹。因此,我们创建了一个用户并共享了日历,现在我正试图通过 Access 2016(希望是 2012)找出 add/change/delete 事件 to/from 另一个用户日历的代码。

下面的代码只是我想弄清楚如何添加所以没有错误检查。事实上,我为此创建了一个数据库。

我确实知道如何将它添加到我自己的日历中,但是将它添加到新的 Exchange 365 用户日历中不起作用。这是我的代码:

Private Sub Command15_Click()
    
    Dim outMail     As Outlook.AppointmentItem
    Dim objNS       As Outlook.NameSpace
    Dim objFolder   As Outlook.MAPIFolder        'get name of other persons folder
    Dim objRecip    As Outlook.Recipient        'other persons name
    Dim strName     As String        'the name or email of the persons folder
    Dim objAppt     As Outlook.AppointmentItem
    Dim objApp      As Outlook.Application

    On Error Resume Next
    ' name of person whose Calendar you want to use - right
    strName = "janet 2"
    Set objNS = objApp.GetNamespace("MAPI")
    Set objRecip = objNS.CreateRecipient(strName)
    Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
    'Set outMail = Outlook.CreateItem(olAppointmentItem)
    Set outMail = objFolder.Items.Add
    outMail.Subject = "test"
    outMail.Location = ""
    outMail.MeetingStatus = olMeeting
    outMail.Start = Me.BegDate
    outMail.End = Me.BegTime
    outMail.RequiredAttendees = strName
    outMail.Body = "test message"
    outMail.Save
    'Set outMail = Nothing
    
End Sub

我让它工作(有点)。我将 Set OutMail 改回原来的设置:

Set OutMail = Outlook.CreateItem(olAppointmentItem)

然后我将 Outmail.Save 更改为 Outmail.Send。

它现在将其放入其他用户的日历中,但未被接受。我需要它按已接受的方式进入。我现在要研究这个。

有效的完整代码:

    Dim outMail As Outlook.AppointmentItem ' meeting or one-time appointment in Calendar folder
    Dim objNS As Outlook.NameSpace ' accessing data sources owned by other users
    Dim objFolder As Outlook.MAPIFolder 'get name of other persons folder
    Dim objRecip As Outlook.Recipient ' Other persons name
    Dim strName As String ' the name or email of the persons folder
    Dim objAppt As Outlook.AppointmentItem
    Dim objApp As Outlook.Application

    'name of person whose calendar you want to use
    strName = "ICT Time Off"

    Set objApp = GetObject(, "Outlook.Application")    'Bind to existing instance of Outlook
    Set objNS = objApp.GetNamespace("MAPI")

    Set objRecip = objNS.CreateRecipient(strName)
                                        
    Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
    'Set outMail = Outlook.CreateItem(olAppointmentItem)
    Set outMail = objFolder.Items.Add
        
    outMail.Subject = "test"
    outMail.Location = ""
    outMail.MeetingStatus = olMeeting
    outMail.Start = Me.BegDate
    outMail.End = Me.EndDate

    outMail.RequiredAttendees = strName
    outMail.Body = "test message"
        
    outMail.Save