【问题标题】:Add event to other user's Outlook calendar将事件添加到其他用户的 Outlook 日历
【发布时间】:2021-02-26 01:22:07
【问题描述】:

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

嗯,更新后的 Exchange 不使用公用文件夹。因此,我们创建了一个用户并共享了日历,现在我正在尝试找出通过 Access 2016(希望是 2012 年)在另一个用户的日历中添加/更改/删除事件的代码。

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

我确实想出了如何将它添加到我自己的日历中,但是将它添加到新的 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

【问题讨论】:

  • On Error Resume Next 隐藏错误。使调试变得不可能。导致一个糟糕的问题,因为没有关于结果的信息。
  • 那么当您单步执行代码时会发生什么?

标签: vba outlook


【解决方案1】:

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

Set OutMail = Outlook.CreateItem(olAppointmentItem)

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

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

【讨论】:

  • 更改设置 OutMail = objFolder.Items.Add 和 Outmail.Send 回 Outmail.Save,现在它会自动保存到其他用户的日历。耶!
【解决方案2】:

完整的代码:

    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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多