1

I'm working on a simple Outlook VBA script to accept all selected meeting requests. Many online examples suggest something like the following code should work:

Sub AcceptItem()
Dim cAppt As AppointmentItem
Dim oRequest As MeetingItem
Dim x As Integer
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)
   oRequest.Send
End If
Next x
End Sub

But the script always fails at oRequest.send -- when I inspect with the debugger, oRequest is always set to Nothing after the Respond line is executed, rather than containing a MeetingItem.

What am I doing wrong?

chris neilsen
  • 52,446
  • 10
  • 84
  • 123
  • 1
    https://stackoverflow.com/questions/65672635/decline-and-delete-meeting-request-in-outlook-using-macro "... cAppt.Respond() returns Nothing when organizer of the meeting has requested NO responses." – niton Feb 15 '23 at 21:31

1 Answers1

1

Before calling the Respond method in the code you need to check the AppointmentItem.ResponseRequested property which returns a boolean that indicates true if the sender would like a response to the meeting request for the appointment.

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)
    If cAppt.ResponseRequested = True Then
      Set oRequest = cAppt.Respond(olMeetingAccepted, True)
      oRequest.Send
    End If
  End If
Next x
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • That does appear to be the problem. But how do I set the category for an accepted appointment if no response is requested? When a response is requested, I was using `oRequest.Categories = "XXX"` but when no response is requested, `oRequest` is `Nothing`, and setting the category on the original appointment item (`cAppt.Categories`) doesn't do anything either. – Adam J. Kessel Feb 15 '23 at 23:24
  • @AdamJ.Kessel Create a question post. – niton Feb 17 '23 at 14:02