'Verify if there are conflicts between 2 outlook meeting using VBA
I'm currently working on a macro for outlook, to create meetings from a specific date.
My macro can create, modify, delete meetings.
I would like to check if there are conflicts between meetings when I create one.
I've tried to use AppointmentItem.Conflicts property, but I couldn't have any good results.
Thank you for your help.
D
Solution 1:[1]
You can use the Recipient.FreeBusy method which returns free/busy information for the recipient. This following VBA example returns a string of free/busy information with one character for each hour (complete format).
Set myRecipient = myNameSpace.CreateRecipient("Nate Sun")
myFBInfo = myRecipient.FreeBusy(#02/05/2022#, 60, True)
To get information for the current user you may use the NameSpace.CurrentUser property which returns the currently logged-on user as a Recipient object, so may call the FreeBusy method on it.
Note, in case of Exchange accounts you may find the ExchangeUser.GetFreeBusy method helpful. It returns a string representing the availability of the ExchangeUser for a period of 30 days from the start date, beginning at midnight of the date specified.
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
Also you may try to get all meeting that starts or ends in a specific interval. The Find/FindNext or Restrict method can help with such tasks. Read more about them in the following articles:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
