MailItem.Reply Event not working as expected

白昼怎懂夜的黑 提交于 2021-01-29 07:54:55

问题


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

回答1:


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.




回答2:


Do you click Reply in the Explorer or Inspector? Your code will only run if you click Reply button in an Inspector.




回答3:


you have to put this into "ThisOutlookSession" - only there it will work!

Option Explicit
Private WithEvents objInspectors As Outlook.Inspectors

Private Sub Application_Startup()
   Set objInspectors = Outlook.Inspectors
end Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
    If Inspector.CurrentItem.Class = olMail Then
            Set newItem = Inspector.CurrentItem
    End If
    Set Inspector = Nothing
End Sub

Public Sub newItem_Open(Cancel As Boolean)
   newItem.BodyFormat = olFormatHTML
   If newItem.Sent = True Then Exit Sub
End Sub

This will work on any new mail-item, I do not know how to make this work only for replys. You could check the subject, if there is an subject already it will be an reply.



来源:https://stackoverflow.com/questions/24029515/mailitem-reply-event-not-working-as-expected

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