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?