vbaoutlookoutlook-2013

MailItem.Reply Event not working as expected


I want to write a script that changes the format of the mail, when I am replying to a text- or rtf-mail, using Outlook 2013. To have something to begin with. I used the reply event described in the MS dev centre. Unfortunately the example does not work as I expect it to. For testing, I put in a simple message box that should pop up after clicking the reply button. I never see that message box. What did I do wrong?

Public WithEvents myItem As MailItem 

Sub Initialize_Handler() 

    Set myItem = Application.ActiveInspector.CurrentItem 

End Sub 


Private Sub myItem_Reply(ByVal Response As Object, Cancel As Boolean) 

    'Set Response.SaveSentMessageFolder = myItem.Parent
    MsgBox "I never see this message box :("

End Sub

Solution

  • To use the method promoted by Microsoft you need this code in ThisOutlookSession. It would be needed if the event code is not in this special class module.

    Private Sub Application_Startup()
        Initialize_handler
    End Sub
    

    The method described in the answer from Max, where code is in Application_Startup rather than Initialize_handler, can be used if all code is in ThisOutookSession.