0

I am using VBA to accept certain calendar invites. When the meeting invite requests a response, I'm able to accept and send the response while setting the category for the copy stored on my calendar with the following script (also discussed here).

Attempt to set category when no response is requested.

For x = Application.ActiveWindow.Selection.Count To 1 Step -1
    If (Application.ActiveWindow.Selection.Item(x).MessageClass = "IPM.Schedule.Meeting.Request") Then
        Set cAppt = Application.ActiveWindow.Selection.Item(x).GetAssociatedAppointment(True)
        Set oRequest = cAppt.Respond(olMeetingAccepted, True)
        If cAppt.ResponseRequested = True Then
            oRequest.Send
            oRequest.Categories = "xxxx"
        Else
            cAppt.Categories = "xxxx"
        End If
    End If
Next x

When the invite does not request a response, no MeetingItem is generated and setting the category on the original AppointmentItem has no effect (e.g. cAppt.Categories = "xxxx").

Community
  • 1
  • 1

2 Answers2

0

After you set the category, you need to save the appointment:

cAppt.Categories = "xxxx"
cAppt.Save
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
0

How do I set the calendar item category with VBA for an appointment request that does not request a response?

You need to set a category on the appointment item in your calendar, not a meeting request in that case.

The Categories property returns or sets a string representing the categories assigned to the Outlook item. If you don't see the category assigned to the item you need call the Save method as Dmitry suggested.

For x = Application.ActiveWindow.Selection.Count To 1 Step -1
  If (Application.ActiveWindow.Selection.Item(x).MessageClass = "IPM.Schedule.Meeting.Request") Then
    Set cAppt = Application.ActiveWindow.Selection.Item(x).GetAssociatedAppointment(True)
    Set oRequest = cAppt.Respond(olMeetingAccepted, True)
    If cAppt.ResponseRequested = True Then
      oRequest.Categories = "xxxx"
      oRequest.Send
    Else
      cAppt.Categories = "xxxx"
      cAppt.Save
    End If
  End If
Next x
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45