MS Outlook Explorer_Close Event

烈酒焚心 提交于 2021-01-29 17:31:22

问题


I have the following code:

Option Explicit

Public WithEvents myOlExp As Outlook.Explorer

' Initiation
Private Sub Application_Startup()

Set myOlExp = Application.ActiveExplorer

End Sub

' Termination
Private Sub myOlExp_Close()

MsgBox "quit"

End Sub

The code itself works fine - with one important limitation (= my problem). The Explorer_Close event is only triggered when multiple Outlook windows are open and these are being closed. However when the last/main Outlook window is being closed, then this event is not triggered.

I have also tried Application_Quit - but when this runs it is no longer possible to process mail items.

Background: I am trying to reorganize certain items when I close Outlook.


回答1:


You must subscribe to each Explorer instance individually and keep these references alive if you want to get events fired each time.

Basically, you need to maintain the list of Explorer objects opened by handling the NewExplorer event which is fired whenever a new explorer window is opened, either as a result of user action or through program code. In the event handler, you may add a new Explorer instance to the collection and remove it in the Close event handler when a corresponding instance is closed.



来源:https://stackoverflow.com/questions/59224587/ms-outlook-explorer-close-event

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