Option Explicit
' In ThisOutlookSession
Private WithEvents myOlInspectors As Inspectors
Private Sub Application_Startup_Temporary()
Set myOlInspectors = Application.Inspectors
End Sub
Private Sub myOlInspectors_NewInspector(ByVal oInspector As Inspector)
' https://learn.microsoft.com/en-us/office/vba/api/outlook.inspectors.newinspector
' Occurs whenever a new inspector window is opened,
' either as a result of user action or through program code
Dim msg As MailItem
If oInspector.CurrentItem.Class = olMail Then
Set msg = oInspector.CurrentItem
If msg.Size > 0 Then
Debug.Print "Subject: " & msg.subject
Debug.Print " Non-zero size message opened."
' Your code here
End If
End If
End Sub
Private Sub myOlInspectors_NewInspector_Test()
myOlInspectors_NewInspector ActiveInspector
End Sub
2条答案
按热度按时间2eafrhcq1#
有多个事件可以考虑用于此类目的。
第一个选项是处理
NewInspector
事件,该事件在新的检查器窗口打开时触发,无论是作为用户操作的结果还是通过程序代码打开的检查器作为参数传递,因此您可以订阅Activate事件,该事件在检查器成为活动窗口时触发,无论是作为用户操作的结果还是通过程序代码。在这个阶段,项目和检查器窗口已经初始化,您可以自由地进行任何自定义。您可能会发现Implement a wrapper for inspectors and track item-level events in each inspector文章很有帮助。
第二个选项是处理MailItem.Reply事件,当用户为某个项选择
Reply
操作时,或者为该项(父对象的示例)调用Reply
方法时,将触发该事件。qij5mzcb2#
Inspectors.NewInspector event
每当打开新的检查器窗口时发生,无论是由于用户操作还是通过程序代码