我在Outlook中有以下ThisOutlookSession
:
Public Sub Application_Startup()
Call GetItemsFolderPath.Initialize
End Sub
和以下GetItemsFolderPath
类模块:
Public WithEvents myOlExp As Outlook.Explorer
Public Sub Initialize()
Set myOlExp = Application.ActiveExplorer
End Sub
Private Sub myOlExp_SelectionChange()
MsgBox "Hello, world"
End Sub
我基本上遵循https://learn.microsoft.com/en-ca/office/vba/api/Outlook.Explorer.SelectionChange
的文档- 代码编译,但它从不显示MsgBox
- 重新启动Outlook使
Application_Startup
被调用不起作用 手动执行
Application_Startup
宏也没有帮助有什么想法-我做错了吗?
当在全局空间中添加Dim GetItemsFolderPath As New GetItemsFolderPath时,代码会正常工作,当您在Outlook中切换文件夹时显示消息框。
ThisOutlookSession:
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
我遇到了以下问题:https://learn.microsoft.com/en-us/outlook/troubleshoot/deployment/macros-in-this-project-disabled-outlook