我们的电子邮件系统正在更新到 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
答案 0 :(得分:0)
我让它工作(有点)。我把 Set OutMail 改回原来的样子:
Set OutMail = Outlook.CreateItem(olAppointmentItem)
然后我将 Outmail.Save 更改为 Outmail.Send。
它现在将其放入其他用户的日历中,但未被接受。我需要它作为 Accepted 进入。我现在要研究这个。
答案 1 :(得分:0)
完整的代码:
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