Question

I have a simple VBA code below where for now I'm just trying to trigger the Forward event as described at http://msdn.microsoft.com/en-us/library/office/aa171259(v=office.11).aspx. It works great if I open a email and try to forward it, but if I try to forward from Outlook's main preview pane window, the MsgBox does not appear.

Any ideas what's causing this or how to make the Forward event run from the preview pane?

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

((updated current working code))

Was it helpful?

Solution

It doesn't trigger because you never set up an event sink on the message being forwarded.

You need to track the Explorer.SelectionChange event, release previously cached items, then set up event handlers on all items in the Explorer.Selection collection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top