0
votes

When I reply to a meeting invite sent to one of my non-default email accounts, Outlook sends the replies from the default account instead of the account the invite was sent to.

I tried using the ItemLoad event to trap this situation and set a MailItem object to use in a MailItem.Reply event. I get a type error message in this line of code below Set NonDefaultMailboxMtgMsg = myObj.

How can I set NonDefaultMailboxMtgMsg to the meeting request's corresponding MailItem object so it will trigger the reply event?

Public WithEvents NonDefaultMailboxMtgMsg As MailItem
Dim MeetingReplyDisplayName As String


Private Sub Application_ItemLoad(ByVal Item As Object)
    
    Dim myObj As Variant
    Set myObj = GetCurrentItem()
      
    If myObj.Class = olMeetingRequest And myObj.Parent.Store.DisplayName _
     <> Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Store.DisplayName Then
     
        Set NonDefaultMailboxMtgMsg = myObj
        MeetingReplyDisplayName = myObj.Parent.Store.DisplayName
    End If
End Sub

Private Sub NonDefaultMailboxMtgMsg_Reply(ByVal Response As Object, Cancel As Boolean)
        Response.SendUsingAccount = MeetingReplyDisplayName
End Sub

Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application
         
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
     
    Set objApp = Nothing
End Function
1
As you reply on a MeetingItem, shouldn't you use MeetingItem_Reply event instead of MailItem ? Set NonDefaultMailboxMtgMsg = myObj fails as myObj is checked for being olMeetingRequest what is a MeetingItem not a MailItem!ComputerVersteher
Thank you. I had originally tried defining NonDefaultMailboxMtgMsg as MeetingItem, but then Private Sub NonDefaultMailboxMtgMsg_Reply(ByVal Response As Object, Cancel As Boolean) was never triggered. Wouldn't the above definition make this a MeetingItem_Reply event?Jeff
Code needs to be in ThisOutlookSessionstackoverflow.com/questions/24029515/…ComputerVersteher
Thank you for the link. I did have my code in ThisOutlookSession, but did not set up Outlook.Inspectors to capture the reply event. I will try that.Jeff

1 Answers

0
votes

The item type received is a meeting request (olMeetingRequest) which is a MeetingItem.

Public WithEvents NonDefaultMailboxMtgMsg As MailItem does not match so you get a type mismatch on Set NonDefaultMailboxMtgMsg = myObj.

Instead usePublic WithEvents NonDefaultMailboxMtgMsg As MeetingItem.


Sample code to demonstrate event triggering on clicking Respond then Reply.

Public WithEvents NonDefaultMailboxMtgMsg As MeetingItem

Dim MeetingReplyDisplayName As String

Private Sub Application_ItemLoad(ByVal Item As Object)
    
    Debug.Print
    Debug.Print "Procedure.......: Application_ItemLoad"
    Debug.Print " TypeName(Item).: " & TypeName(Item)
    
    Dim myObj As Object
    Set myObj = GetCurrentItem()
    Debug.Print " TypeName(myObj): " & TypeName(myObj)
    
    If myObj.Class = olMeetingRequest Then
        If myObj.Parent.Store.DisplayName <> GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Store.DisplayName Then
            Set NonDefaultMailboxMtgMsg = myObj
            MeetingReplyDisplayName = myObj.Parent.Store.DisplayName
        End If
    End If
    
End Sub

Private Sub NonDefaultMailboxMtgMsg_Reply(ByVal Response As Object, Cancel As Boolean)
    Debug.Print
    Debug.Print "Procedure.........................: NonDefaultMailboxMtgMsg_Reply"
    Debug.Print " TypeName(NonDefaultMailboxMtgMsg): " & TypeName(NonDefaultMailboxMtgMsg)
    Debug.Print " TypeName(Response)...............: " & TypeName(Response)
    MsgBox "Reply event triggered"
End Sub

Function GetCurrentItem() As Object
    
    Select Case TypeName(ActiveWindow)
    
        Case "Explorer"
            On Error Resume Next
            Set GetCurrentItem = ActiveExplorer.Selection.Item(1)
            On Error GoTo 0
            
        Case "Inspector"
            Set GetCurrentItem = ActiveInspector.currentItem
            
    End Select
     
End Function