How do you reference the mailitem in an Explorer preview pane?




I would like to know how I could trap or determine programmatically
when a user is reading an email message in the preview pane. In other
words, without double clicking a message, which normally opens an
inspector window to display that email message, I would like to
programmatically determine when a user is just reading the message in
the preview pane. Also, in Outlook 2000, when a user single clicks
another message, that message's body then appears in the preview pane
normally. Is there any event that can tell me when a user is
previewing a message? The closest event is the SelectionChange event
of the Explorer object.

I do know there is an event for the Explorer Object called
SelectionChange and that seems to work. I did a test by putting in a
message box inside this event and sure enough the message box came up
when I browsed to another message (clicked onto a message).

What I want to do is run a program when the user clicks the message. I
have a VB 6 COM Add-in program running perfectly when the user double
clicks a message that opens an inspector window (I declared and
instantiated an object variable of type MailItem that points to the
mail item when a new inspector window opens – code snippet given
below.). However, since an inspector window isn't being opened, I
can't use the same code. I am also only interested in emails in the
inbox when I run my program.

Private Sub oAppInspectors_NewInspector(ByVal Inspector As
'When a new Inspector is opened
Set oAppInspector = Inspector
If oAppInspector.CurrentItem.Class = olMail Then 'only Mail items
Set oAppMail = oAppInspector.CurrentItem
End If
End Sub

I also have events for the object variable oAppMail such as Send,
Reply, and Read, which are also working great.

I guess what I am asking is how do you set an object variable of
MailItem type to the currently viewed email message in the preview
pane? Once I have that, I think I can use similar code to what I have
now. However, I don't think there is an active inspector window to use
so I am at loss.

Any help is most appreciated. Thanks.

Ken Slovak - [MVP - Outlook]

SelectionChange and the Selection collection are what you get in an
Explorer. Any item that is read in the preview pane fires the Read
event for that item but you'd need to instantiate each member of the
Selection collection and put the items in a selection wrapper class to
fire the event individually for each item.

You can look at the ItemsCB COM addin sample on the Resources page at to see an example of an Explorer wrapper. I've used
similar code to wrap Inspectors, Items and so on.

Ken Slovak
[MVP - Outlook]
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
Extended Reminders

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question