title: For Each to Iterate through a List of Outlook Calendar Items
body: <p>I want to change the time zone of all items in an Outlook 2010 calendar.</p>
  
  <p>I am confused as to how one would work with the items of a collection as they are iterated in the loop. My main background is in Java, and as I understand loops there a single variable is used as a dummy variable that will take the value of all items in the collection, in turn. No special assignment is usually required for such FOR loops. Do you need to manually advance the variable in some way so as to keep the loop going?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Public Sub TZFix()
  
      Dim oAppointmentItem As Outlook.AppointmentItem
      Dim tzs As Outlook.TimeZones
      Dim tzCentral As Outlook.TimeZone
      Dim oAppointments As Object
      Dim oNS As Outlook.NameSpace
  
      Set oNS = oOutlook.GetNamespace("MAPI")
      Set oAppointments = oNS.GetDefaultFolder(olFolderCalendar)
      Set tzs = Application.TimeZones
      Set tzCentral = tzs("Central Standard Time")
  
      For Each oAppointmentItem In oAppointments.Items
          Set oAppointmentItem.StartTimeZone = tzCentral
          Set oAppointmentItem.EndTimeZone = tzCentral
      Next
  
  End Sub
  </code></pre>
  
  <p>I believe that there is an issue with variable assignment within the loop, as I get an <code>Error 91: Object Variable or With block variable not set</code> error whenever I run it.</p>