0

When replying to a meeting invite sent to a non-default account in Outlook 365 desktop, it typically responds from the default account. The following code fixed that problem, but recently stopped working correctly.

My replies used to say, "Yes, NONdefaultrecipientemail@gmail.com will attend" "From: nondefaultrecipientemail@gmail.com."

Now it says, "Yes, Defaultemail@gmail.com will attend" "From: nondefaultrecipientemail@gmail.com on behalf of Defaultemail@gmail.com."

Any ideas on why this no longer works and how to fix it?

Thanks!

Sub MeetingResponse(myAction As String) 
'If a meeting request is sent to the non-default email address, replies, etc., will normally come from the default email.
'This macro changes the send from email address to the correct one.

     Dim myNameSpace As Outlook.NameSpace
     Dim myAppt As Outlook.AppointmentItem
     Dim oMtgResponse, oReplyForward, oMtgRequest As Outlook.MeetingItem
     
     Dim oAccount As Outlook.Account
     Dim SendAcct As Variant
     Dim SendEmailAddr As String
     Dim FolderParent As String
     
     Set myNameSpace = Application.GetNamespace("MAPI")

    'Determine which account invite was sent to.
    FolderParent = Application.ActiveExplorer.CurrentFolder.Parent
    For Each oAccount In Application.Session.Accounts
        If oAccount.DeliveryStore.GetDefaultFolder(olFolderInbox).Parent = FolderParent Then
            SendAcct = oAccount.DisplayName
            Exit For
        End If
    Next
     
     Set oMtgRequest = GetCurrentItem()
             
     If TypeName(oMtgRequest) <> "Nothing" Then
     
        Set myAppt = oMtgRequest.GetAssociatedAppointment(True)
        
        'Set send from account
        For Each oAccount In Application.Session.Accounts
            If oAccount = SendAcct Then
                Select Case UCase(myAction)
                
                    Case "ACCEPT"
                        Set oMtgResponse = myAppt.Respond(olResponseAccepted, True)
                        oMtgResponse.SendUsingAccount = oAccount
                        oMtgResponse.Display
                        oMtgRequest.Delete
                        
                    Case "DECLINE"
                        Set oMtgResponse = myAppt.Respond(olResponseDeclined, True)
                        oMtgResponse.SendUsingAccount = oAccount
                        oMtgResponse.Display
                        oMtgRequest.Delete
                
                    'Original inviter may be notified this was forwarded.
                    Case "FORWARD"
                        Set oReplyForward = oMtgRequest.Forward
                        oReplyForward.SendUsingAccount = oAccount
                        oReplyForward.Display
                    
                    'Original inviter will not be notified this was forwarded.
                    'Creates new appointment based on original one.
                    Case "FORWARDSILENT", "FORWARD SILENT"
                        Dim oAppt As AppointmentItem
                        Set oAppt = Application.CreateItem(olAppointmentItem)
                         
                        With oAppt
                            .MeetingStatus = olMeeting
                            .Subject = "Accepted: " & myAppt.Subject
                            .Start = myAppt.Start
                            .Duration = myAppt.Duration
                            .Location = myAppt.Location
                            .Body = myAppt.Body
                            .Display
                            .SendUsingAccount = oAccount
                        End With
                        
                    Case "REPLY"
                        Set oReplyForward = oMtgRequest.reply
                        oReplyForward.SendUsingAccount = oAccount
                        oReplyForward.Display
                        
                    Case "FORWARDASATTACHMENT", "FORWARD AS ATTACHMENT"
    
                    Case Else
                        MsgBox "Could not process!  Incorrect action provided.", vbCritical + vbOKOnly
                        
                End Select
                
                
                Exit For
            End If
        Next
      
     End If
End Sub 'MeetingResponse
Jeff
  • 3
  • 4

1 Answers1

0

The MeetingItem.SendUsingAccount property allows setting an Account object that represents the account to use to send the MeetingItem. But in your code you are trying to set the property to a string which contains the display name of the Account chosen.

Declare an instance of the Account class in the code and initialize it in the following way:

FolderParent = Application.ActiveExplorer.CurrentFolder.Parent
    For Each oAccount In Application.Session.Accounts
        If oAccount.DeliveryStore.GetDefaultFolder(olFolderInbox).Parent = FolderParent Then
            Set SendAcct = oAccount
            Exit For
        End If
    Next

Then you can set the MeetingItem.SendUsingAccount property correctly:

oMtgResponse.SendUsingAccount = oAccount
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45