我目前正在为outlook开发一个宏,以创建特定日期的会议。
我的宏可以创建、修改、删除会议。
当我创建一个会议时,我想检查会议之间是否有冲突。
我尝试过使用AppointmentItem.Conflicts属性,但是我无法获得任何好的结果。
谢谢你的帮助。
D
发布于 2022-05-02 08:02:36
您可以使用Recipient.FreeBusy方法来返回收件人的空闲/繁忙信息。下面的VBA示例返回一串空闲/繁忙信息,每个小时有一个字符(完全格式)。
Set myRecipient = myNameSpace.CreateRecipient("Nate Sun")
myFBInfo = myRecipient.FreeBusy(#02/05/2022#, 60, True)要获取当前用户的信息,可以使用NameSpace.CurrentUser属性,该属性将当前登录用户作为收件人对象返回,因此可以对其调用FreeBusy方法。
注意,如果使用Exchange帐户,您可能会发现ExchangeUser.GetFreeBusy方法很有用。它返回一个字符串,表示从开始日期起30天内的ExchangeUser可用性,从指定日期的午夜开始。
Sub GetManagerOpenInterval()
Dim oManager As ExchangeUser
Dim oCurrentUser As ExchangeUser
Dim FreeBusy As String
Dim BusySlot As Long
Dim DateBusySlot As Date
Dim i As Long
Const SlotLength = 60
'Get ExchangeUser for CurrentUser
If Application.Session.CurrentUser.AddressEntry.Type = "EX" Then
Set oCurrentUser = _
Application.Session.CurrentUser.AddressEntry.GetExchangeUser
'Get Manager
Set oManager = oManager.GetExchangeUserManager
If oManager Is Nothing Then
Exit Sub
End If
FreeBusy = oManager.GetFreeBusy(Now, SlotLength)
For i = 1 To Len(FreeBusy)
If CLng(Mid(FreeBusy, i, 1)) = 0 Then
'get the number of minutes into the day for free interval
BusySlot = (i - 1) * SlotLength
'get an actual date/time
DateBusySlot = DateAdd("n", BusySlot, Date)
'To refine this function, substitute actual
'workdays and working hours in date/time comparison
If TimeValue(DateBusySlot) >= TimeValue(#8:00:00 AM#) And _
TimeValue(DateBusySlot) <= TimeValue(#5:00:00 PM#) And _
Not (Weekday(DateBusySlot) = vbSaturday Or _
Weekday(DateBusySlot) = vbSunday) Then
Debug.Print oManager.name & " first open interval:" & _
vbCrLf & _
Format$(DateBusySlot, "dddd, mmm d yyyy hh:mm AMPM")
Exit For
End If
End If
Next
End If
End Sub此外,您也可以尝试使所有会议在一个特定的间隔内开始或结束。Find/FindNext或Restrict方法可以帮助完成这些任务。在以下文章中可以了解更多关于这些问题的内容:
https://stackoverflow.com/questions/72083728
复制相似问题