我在下面有一个简单的VBA代码,现在我只是试图按http://msdn.microsoft.com/en-us/library/office/aa171259(v=office.11).aspx所述触发Forward事件。如果我打开电子邮件并尝试转发它,它会很有效,但如果我尝试从Outlook的主预览窗格窗口转发,则MsgBox
不会出现。
是什么原因造成了这个或如何从预览窗格运行Forward事件?
Public WithEvents myOlExp As Outlook.Explorer
Public WithEvents goInspectors As Outlook.Inspectors
Public WithEvents myMailItem As Outlook.mailItem
Private Sub Application_Startup()
Set goInspectors = Outlook.Application.Inspectors
Set myOlExp = Application.ActiveExplorer
End Sub
Private Sub goInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class = olMail Then
Set myMailItem = Inspector.CurrentItem
Else
Exit Sub
End If
End Sub
Private Sub myMailItem_Forward(ByVal Forward As Object, Cancel As Boolean)
MsgBox "hello?"
End Sub
Private Sub myOlExp_SelectionChange()
MsgBox "here"
MsgBox myOlExp.Selection.Count & " items selected."
' Set myMailItem = myOlExp.Selection.Item
End Sub
((更新当前工作代码))
答案 0 :(得分:0)
它不会触发,因为您从未在转发的邮件上设置事件接收器。
您需要跟踪Explorer.SelectionChange事件,释放以前缓存的项目,然后在Explorer.Selection集合中的所有项目上设置事件处理程序。