未调用Outlook VBA事件处理程序

未调用Outlook VBA事件处理程序,vba,outlook,Vba,Outlook,我在Outlook中有以下ThisOutlookSession: Public Sub Application_Startup() Call GetItemsFolderPath.Initialize End Sub 以及以下GetItemsFolderPathclass模块: Public WithEvents myOlExp As Outlook.Explorer Public Sub Initialize() Set myOlExp = Application.ActiveE

我在Outlook中有以下
ThisOutlookSession

Public Sub Application_Startup()
    Call GetItemsFolderPath.Initialize
End Sub
以及以下
GetItemsFolderPath
class模块:

Public WithEvents myOlExp As Outlook.Explorer

Public Sub Initialize()
 Set myOlExp = Application.ActiveExplorer
End Sub

Private Sub myOlExp_SelectionChange()
 MsgBox "Hello, world"
End Sub
我基本上是在遵循

  • 代码可以编译,但从不显示MsgBox
  • 重新启动Outlook,因此调用了应用程序启动,但此操作无效
  • 手动执行
    应用程序\u启动
    宏也没有帮助

有什么想法吗?我做错了什么?

在全局空间中将Dim GetItemsFolderPath添加为新的GetItemsFolderPath时,代码会正常工作,在Outlook中切换文件夹时会显示messagebox

本次展望会议:

Option Explicit

Dim GetItemsFolderPath As New GetItemsFolderPath 'Instantiate the class

'***************************************************
'* Outlook start
'*
Public Sub Application_Startup()
    Call GetItemsFolderPath.Initialize
End Sub
类模块GetItemsFolderPath:

Option Explicit

Public WithEvents myOlExp As Outlook.Explorer

Public Sub Initialize()
    Set myOlExp = Application.ActiveExplorer
End Sub

Private Sub myOlExp_SelectionChange()
    MsgBox "Hello, world"
End Sub

我遇到了以下问题:

可能重复@niton:我已经在跟踪链接问题中的已接受项,因此它不是重复项。这是VBA
调用GetItemsFolderPath.Initialize
?这是什么意思?为什么不应该是VBA?我不认识。关于使用类模块(而不是
ThisOutlookSession
)的答案似乎很流行。我看不到有人使用它。谢谢,实例化这个类也不见了。但真正的问题是:看我的答案。这不是最初的问题。我回答了。你应该把我的答案标记为解决问题的答案,然后写一个新问题。