Which Outlook event to use?

S

SanjaDj

I am using Ribbon customization to add button that (when clicked) will create
my CustomTaskPane in Mail Item.
What I have now is that if Mail Item is closed and CustomTaskPane is not
closed then next time I open new or existing Mail Item my CustomTaskPane is
immediately shown.
I would like to close this task automatically when Mail Item is closed just
I don't know which event to use.
I have tried with oMailItem.Close and oMailItem.Unload but I don't get in
there upon closing Mail Item.
 
K

Ken Slovak - [MVP - Outlook]

Unload may not fire for a while, it fires when Outlook unloads an item from
its cache. That is not synchronous with closing the item.

Item.Close should work, you can also try Inspector.Close.
 
K

Ken Slovak - [MVP - Outlook]

You should be using the RTM version instead of a beta release, but that
makes no difference in handling either Inspector.Close or Item.Close. I was
handling those events even with the alpha DF4 release.

I'd suspect you are not using class level objects when trying to set up your
event handlers and therefore the garbage collector has removed your
variables and event handlers by the time the events do fire. You need to use
objects declared at a level where they won't be garbage collected.

There are lots of examples of this in this group and others you can google
for, at www.outlookcode.com and in the MS example programs for Outlook 2007.
I'd suggest you look those over.
 
K

Ken Slovak - [MVP - Outlook]

It's necessary to use wrappers and/or collections if you want to handle
events for multiple open items or open Explorers and to keep your objects
alive so the garbage collector doesn't remove them. If only handling events
for say 1 Explorer you can just use a class level object declared in a class
that has persistence for the life of your addin to keep it alive.

There are KB articles, sample code and books that all use these techniques
and have since Outlook 2000 was released and we had COM addins available.
One of the first examples was ItemsCB in VB6, released for Building
Applications with Outlook 2000.
 
K

Ken Slovak - [MVP - Outlook]

The What's New for Developers section at Office Online at MSDN has a lot of
articles about what's new in Outlook 2007 and there are a number of articles
about VSTO 2005 SE on the VSTO pages at MSDN.
 

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

Top