Function getLocation() As String
Dim oApp As Outlook.Application, oCal As Outlook.Folder, appt As Outlook.AppointmentItem
Dim explorerInstance As Outlook.Explorer, objNS As Outlook.NameSpace
Dim ofldItems As Outlook.Items, sortItems As Outlook.Items
Dim tdystart As Date, tdyend As Date
Dim sRestrict As String
Dim myRecipient As Outlook.Recipient
tdystart = DateSerial(Year(Now), Month(Now), Day(Now))
tdyend = DateSerial(Year(tdystart), Month(tdystart), Day(tdystart) + 2)
Set oApp = CreateObject("Outlook.application")
Set objNS = oApp.GetNamespace("MAPI")
Set myRecipient = objNS.CreateRecipient("learning")
myRecipient.Resolve
If myRecipient.Resolved Then
Set oCal = objNS.GetSharedDefaultFolder(myRecipient, olFolderCalendar)
End If
If oCal Is Nothing Then
For Each explorerInstance In oApp.Explorers
If InStr(1, explorerInstance.Caption, "Calendar") > 0 Then
Set oCal = explorerInstance.CurrentFolder
Exit For
End If
Next
If oCal Is Nothing Then
Exit Function
End If
End If
Set ofldItems = oCal.Items
ofldItems.Sort ("[Start]")
sRestrict = "[Start] >= '" & tdystart & "' and [End] <= '" & tdyend & "'"
Set sortItems = ofldItems.Restrict(sRestrict)
sortItems.Sort ("[Subject]")
Dim myRecurrPatt As Outlook.RecurrencePattern, myException As Outlook.Exception
Dim myExDate As Date, myRecurrAppt As AppointmentItem, D1 As Date, D2 As Date
For Each appt In sortItems
If appt.Subject = "Hold For Onboarding - Matrix Welcome and Office Orientation" Then
tdystart = tdystart + TimeSerial(Hour(appt.Start), Minute(appt.Start), Second(appt.Start))
Set myRecurrPatt = appt.GetRecurrencePattern
On Error Resume Next
Set myRecurrAppt = myRecurrPatt.GetOccurrence(tdystart)
If Not myRecurrAppt Is Nothing Then
getLocation = myRecurrAppt.Location
Else
For Each myException In myRecurrPatt.Exceptions
myExDate = 0
myExDate = myException.AppointmentItem.Start
D1 = DateSerial(Year(myExDate), Month(myExDate), Day(myExDate))
D2 = DateSerial(Year(tdystart), Month(tdystart), Day(tdystart))
If D1 >= D2 And D1 <= D2 + 2 Then
getLocation = myException.AppointmentItem.Location
Exit For
End If
Next
End If
Exit For
End If
Next appt
MsgBox getLocation
Set oApp = Nothing
Set objNS = Nothing
Set oCal = Nothing
Set ofldItems = Nothing
Set sortItems = Nothing
Set appt = Nothing
Set myRecurrPatt = Nothing
End Function