Auto-Decline Meeting Invite Run-Time Error 91: Object variable or With block variable not set

限于喜欢 提交于 2021-01-29 19:52:04

问题


I found the code for Auto-Decline a meeting request in several locations.

In my Outlook 2013 as an action for a rule, it is stopping on the line intended to discard instead of sending the reply.

The meeting organizer does not need a response from everyone. As it is on the group calendar, I don't need it on my personal as they are not meetings I get involved with.

The Outlook rule is aborting the script and jumping out before a couple of additional actions (mark as read and delete) when it hits the Run-time error.

This is resulting in the invite remaining in my Inbox and I don't know what with spamming the organizer.

Sub AutoDeclineMeetings(oRequest As MeetingItem)

If oRequest.MessageClass <> "IPM.Schedule.Meeting.Request" Then
    Exit Sub
End If

Dim oAppt As AppointmentItem
Set oAppt = oRequest.GetAssociatedAppointment(False)

Dim oResponse
Set oResponse = oAppt.Respond(olMeetingDeclined, True)
oResponse.Close (olDiscard)

'These actions I added for my rule to discard the invite from the inbox.
oRequest.UnRead = False
oRequest.Delete

End Sub

On the line oResponse.Close (olDiscard) I am receiving

Run-Time error 91: Object variable or With block variable not set.

I created a temporary macro for testing that takes the currently selected meeting invite in Outlook, and feeds it into the AutoDecline script. This is how I get the error to show itself.

Sub TestMacro()

Dim TestItem As MeetingItem
Set TestItem = ActiveExplorer.Selection.Item(1)
Call AutoDeclineMeetings(TestItem)

End Sub

I am expecting the Decline response to be discarded instead of being sent to the meeting originator so I don't spam them.


回答1:


I don't think you need to do anything with the response if no response is needed. I believe you are getting the error because you are trying to close the response window when it's not open. You could try changing the following line just to see if it gets rid of the error:

Set oResponse = oAppt.Respond(olMeetingDeclined, False, True)

I have similar macros and I simply don't do anything if no response is requested. For example:

Set oResponse = oAppt.Respond(olMeetingDeclined, True)
If oAppt.ResponseRequested Then
    oResponse.Send
End If

oRequest.UnRead = False
oRequest.Delete


来源:https://stackoverflow.com/questions/56172051/auto-decline-meeting-invite-run-time-error-91-object-variable-or-with-block-var

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!