0

Continuation from another question: VBA: Read outlook calendar - not reading recurring appointments?

From the outlook calendar, I'm reading / parsing / sorting the work week to create a summary. I had a previous issue where recurring appointments were not being read - now sorted.

Now - If during the work week I delete a recurring event, say due to holiday, it still shows up in my summary. I can't figure out any parameters within the object to test if its been removed from this week. Recommendations?

Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.GetDefaultFolder(olFolderCalendar)
Set olColItems = olFolder.Items

sFilter = "[START] >= '" & sDateStart & "' And [End] <= '" & sDateEnd & "'"
Set olColFilteredItems = olColItems.Restrict(sFilter)

For Each oItem In olColFilteredItems
    aImport(iCount, 1) = oItem.Subject
    aImport(iCount, 2) = oItem.Start
    aImport(iCount, 3) = oItem.End
    aImport(iCount, 4) = oItem.Location
Next oItem    

Kind regards, Max

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
MaxK-2773298
  • 28
  • 1
  • 6
  • What code do you use now? How do you delete an appointment item? – Eugene Astafiev May 22 '15 at 17:31
  • Apologies - poor explanation. I updated the original post.The recurring event is deleted from within outlook calendar. So its visibly removed from the work week. My reading of the workweek still captures the deleted event as it is still recurring. Cheers, – MaxK-2773298 May 22 '15 at 20:01

3 Answers3

1

You need to set the IncludeRecurrences property. Instead of using Restrict, Sort by Start property and set IncludeRecurrences property to true.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • I'm confused. My recurring appointments appear just fine with the above method. Does using the IncludeRecurrences property provide another way of checking if the appointment has been removed from the calendar? IE: The recurring appointment exists, I remove it from my calendar for this week as I missed the meetings (next week I'll attend), yet the code still counts the recurring appointment as present for this week. – MaxK-2773298 May 28 '15 at 16:54
  • Let's get the terminology right. Firstly, recurrence instances do not physically exist (think o an appointment with no end date) unless you modify an instance; at that moment the exception is created - it is stored as an attachment on the master appointment. If you delete a recurrence instance, the recurrence blob stored on the master appointment is modified to record that there is a hole in the recurrence pattern, If you sort the collection and set IncludeRecurrences to true, OOM expands the recurrence pattern and creates fake AppointmentItem objects that do not physically exist. – Dmitry Streblechenko May 28 '15 at 17:41
0

Dmitry is right, to retrieve all Outlook appointment items from the folder that meets the predefined condition, you need to sort the items in ascending order and set the IncludeRecurrences to true. You will not catch recurrent appointments if you don’t do this before using the Restrict method!

See How To: Use Restrict method in Outlook to get calendar items for more information (a sample code is included).

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Hah. Thanks so much. I re-read Dmitry's comment about 10 times before my brain clued in. The above linked really helped too. This is all it took: – MaxK-2773298 May 28 '15 at 21:37
0

Hah. Thanks so much. I re-read Dmitry's comment about 10 times before the fog parted. The above linked really helped too. This is all it took:

Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.GetDefaultFolder(olFolderCalendar)
Set olColItems = olFolder.Items

olColItems.IncludeRecurrences = True    '<-- these two lines here fix my issue
olColItems.Sort ("[Start]")             '<--

sFilter = "[START] >= '" & sDateStart & "' And [End] <= '" & sDateEnd & "'"
Set olColFilteredItems = olColItems.Restrict(sFilter)

For Each oItem In olColFilteredItems
    aImport(iCount, 1) = oItem.Subject
    aImport(iCount, 2) = oItem.Start
    aImport(iCount, 3) = oItem.End
    aImport(iCount, 4) = oItem.Location
Next oItem
MaxK-2773298
  • 28
  • 1
  • 6