I am writing a new and revised version of a VBA Outlook macro that will go through all appointment's in a user's calendar and change every recurring series' time zone to Central Standard. No matter what I do, however, I cannot seem to get it to access the recurrence properly. At present, when I debug the macro it will fail the first time a call is made to ex.AppointmentItem.Subject (in the Debug.Print statement after the recurrence pattern rPattern is defined). The central question here is: how can I access and modify an entire series of recurring appointments at one time? Can I a) modify the master appointment, b) iterate through all appointments in the series (which may not set all future occurrences as I need it to), or c) iterate through the exceptions collection and modify the recurrence from there? I have been told that iterating through the exceptions collection (although misleading in name) is the only way to modify the recurrence. Is this correct?
I deeply appreciate any help you can provide, thanks!
Note: The aItem<>Null was commented out as a test, for some reason checking for a Null item (even tried Nothing keyword) always caused an error.
Public Sub IterateAll()
Dim olApp As New Outlook.Application
Dim aObject As Object
Dim calCollection As Outlook.Items
Dim tzs As Outlook.TimeZones
Dim tzCentral As Outlook.TimeZone
Dim tzUTC As Outlook.TimeZone
Dim olNameSpace As Outlook.NameSpace
Dim rPattern As Outlook.RecurrencePattern
Dim ex As Outlook.Exception
Dim s As Outlook.TimeZone
Dim e As Outlook.TimeZone
Set olNameSpace = olApp.GetNamespace("MAPI")
Set calCollection = olNameSpace.GetDefaultFolder(olFolderCalendar).Items
Set tzs = Application.TimeZones
Set tzCentral = tzs("Central Standard Time")
Set tzUTC = tzs("UTC")
For Each aObject In calCollection
If aObject.IsRecurring Then
Set rPattern = aObject.GetRecurrencePattern
Debug.Print ("Subject: " + aObject.Subject)
Debug.Print ("Old Time Zone is " & aObject.StartTimeZone)
aObject.StartTimeZone = tzCentral
aObject.EndTimeZone = tzCentral
Debug.Print ("New Time Zone is " & aObject.StartTimeZone)
aObject.Save
End If
Next
End Sub
I was able to access all recurring appointments. See this sample. I am using late binding with Outlook.
FOLLOWUP