0

I want to accept or tentatively accept meeting requests in Outlook, depending on whether I have a meeting at that time. I've got the rule set up; it runs the VBA as far as I know, but the code isn't working. I can't find the issue with it.

Sub AcceptDecline(oRequest As MeetingItem)

If oRequest.MessageClass <> "IPM.Schedule.Meeting.Request" Then
    Exit Sub 'if this messageclass isn't a meeting request
End If

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

Dim myAcct As Outlook.Recipient
Dim myFB As String

Set myAcct = Session.CreateRecipient("roconnor@pattonair.com")

myFB = myAcct.FreeBusy(oAppt.Start, 5, False) 'gets the free or busy status of my calendar

Dim oResponse
Dim i As Long
Dim test As String

i = (TimeValue(oAppt.Start) * 288)
test = Mid(myFB, i - 2, (oAppt.Duration / 5) + 2)

If InStr(1, test, "1") Then
    Set oResponse = oAppt.Respond(olMeetingTentative, True)
    oResponse.Display
    oResponse.Send

Else
    Set oResponse = oAppt.Respond(olMeetingAccepted, True)
    oResponse.Display
    oResponse.Send
End If
End Sub
Michael
  • 8,362
  • 6
  • 61
  • 88
TechnicalTophat
  • 1,655
  • 1
  • 15
  • 37
  • Have you debugged the code? – Nathan_Sav Jun 23 '16 at 10:34
  • @Nathan_Sav I'm afraid I wouldn't know how... I found [this question](http://stackoverflow.com/questions/5029141/debugging-an-outlook-2007-script-fired-by-a-rule) but it doesn't explain how to inject the MeetingItem paramter, and it appears the object can't be created (see [this ref](https://msdn.microsoft.com/en-us/library/office/ff868714.aspx)) – TechnicalTophat Jun 23 '16 at 10:44
  • Use breakpoints, have a quick look on google. I triesd something similar, so check out the answer to this http://stackoverflow.com/questions/32974269/get-meeting-time-when-accepting-meeting – Nathan_Sav Jun 23 '16 at 11:00

1 Answers1

1

If the meeting request automatically creates a meeting that is tentatively accepted then free busy indicates you are busy. The response will always be tentative accept.

File-> Options-> Mail-> Tracking-> disable: Automatically process meeting requests and responses to meeting requests and polls

https://www.msoutlook.info/question/do-not-automatically-accept-meeting-as-tentative

If that is not the problem then open the request, which is not automatically marked tentative, and step through with:

Private Sub AcceptDecline_test()
    AcceptDecline ActiveInspector.currentItem
End Sub
niton
  • 8,771
  • 21
  • 32
  • 52