Hi,
I have some code to modify start dates for appointments depending on whether they are recurring or not, this was coded for Outlook 2003:
(txtTiempo, cmbUdTiempo, cmbSensitivity, cmbFlexibilidad are a textBox and Combo Boxes in a Form; optAlta, optNormal and optBaja are Radio Buttons)
Private m_ApptsSelection As Selection
Private Sub cmdActualizar_Click()
Dim myAppt As AppointmentItem, bChanged, importance
Set m_ApptsSelection = Outlook.Application.ActiveExplorer.Selection
For Each myAppt In m_ApptsSelection
bChanged = False
If txtTiempo.Value * 1 <> 0 Then bChanged = True
If Not myAppt.IsRecurring Then
myAppt.Start = DateAdd(cmbUdTiempo.Value, txtTiempo.Value * 1, myAppt.Start)
Else
myAppt.GetRecurrencePattern.PatternStartDate = DateAdd(cmbUdTiempo.Value, txtTiempo.Value * 1, myAppt.GetRecurrencePattern.PatternStartDate)
End If
If myAppt.Sensitivity <> cmbSensitivity.Value Then myAppt.Sensitivity = cmbSensitivity.Value: bChanged = True
If myAppt.BusyStatus <> cmbFlexibilidad.Value Then myAppt.BusyStatus = cmbFlexibilidad.Value: bChanged = True
importance = (optAlta And olImportanceHigh) Or (optNormal And olImportanceNormal) Or (optBaja And olImportanceLow)
If myAppt.importance <> importance Then myAppt.importance = importance: bChanged = True
If bChanged Then myAppt.Save
Next
Set myAppt = Nothing
End Sub
This worked perfectly in Outlook 2003 for both recurring and non recurring appointments. Does not in Outlook 365, for recurring ones.
I get this error message:
Sin título.jpg
and when debugging, i inmediately get a second error message:
Sin título2.jpg
Trying to find out why I read in Office help that
When you work with recurring appointment items, you should release any prior references, obtain new references to the recurring appointment item before you access or modify the item, and release these references as soon as you are finished and have saved the changes. This practice applies to the recurring
AppointmentItem object, and any
Exception or
RecurrencePattern object. To release a reference in Visual Basic for Applications (VBA) or Visual Basic, set that existing object to
Nothing. In C#, explicitly release the memory for that object. For a code example, see the topic for the
AppointmentItem object.
Note that even after you release your reference and attempt to obtain a new reference, if there is still an active reference, held by another add-in or Outlook, to one of the above objects, your new reference will still point to an out-of-date copy of the object. Therefore, it is important that you release your references as soon as you are finished with the recurring appointment.
I suppose that might be the clue, I tried to update code to this:
Private m_ApptsSelection As Selection
Private Sub cmdActualizar_Click()
Dim myAppt As AppointmentItem, bChanged, importance, icSel
Dim ApptRecPatt As RecurrencePattern
Set m_ApptsSelection = Outlook.Application.ActiveExplorer.Selection
For icSel = 1 To m_ApptsSelection.Count
Set myAppt = m_ApptsSelection.item(icSel)
bChanged = False
If txtTiempo.Value * 1 <> 0 Then bChanged = True
If Not myAppt.IsRecurring Then
myAppt.Start = DateAdd(cmbUdTiempo.Value, txtTiempo.Value * 1, myAppt.Start)
Else
Set ApptRecPatt = myAppt.GetRecurrencePattern
Set myAppt = Nothing
If ApptRecPatt.Exceptions.Count > 0 Then
Stop ' TO-DO: update exceptions
End If
ApptRecPatt.PatternStartDate = DateAdd(cmbUdTiempo.value, txtTiempo.value * 1, ApptRecPatt.PatternStartDate)
Set myAppt = m_ApptsSelection.item(icSel)
'myAppt.Save: DOES NOT WORK, I GET AN ERROR.
End If
If myAppt.Sensitivity <> cmbSensitivity.Value Then myAppt.Sensitivity = cmbSensitivity.Value: bChanged = True
If myAppt.BusyStatus <> cmbFlexibilidad.Value Then myAppt.BusyStatus = cmbFlexibilidad.Value: bChanged = True
importance = (optAlta And olImportanceHigh) Or (optNormal And olImportanceNormal) Or (optBaja And olImportanceLow)
If myAppt.importance <> importance Then myAppt.importance = importance: bChanged = True
If bChanged Then myAppt.Save ' DOES NOT WORK, I GET AN ERROR.
Next
Set myAppt = Nothing
End Sub
marked instructions do not work. I want it to work for Outlook 365. Can anyone help to fix this? Thanks.