本文介绍了如何在 Application_Quit 事件之前触发代码来处理项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

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

代码运行但当最后一个/主 Outlook 窗口关闭时,不会触发此事件.

The code runs but when the last/main Outlook window is being closed, this event is not triggered.

我也尝试过 Application_Quit - 但是当它运行时,它不再可能处理邮件项目.

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

背景:我试图在关闭 Outlook 时重新组织某些项目.

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

推荐答案

您必须单独订阅每个 Explorer 实例,并且如果您希望每次都触发事件,请保持这些引用处于活动状态.

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

基本上,您需要维护通过处理 事件,每当打开新的资源管理器窗口时都会触发该事件,无论是由于用户操作还是通过程序代码.在事件处理程序中,您可以向集合中添加一个新的 Explorer 实例并在 Close 相应实例关闭时的事件处理程序.

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.

这篇关于如何在 Application_Quit 事件之前触发代码来处理项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 20:52