In general with WordMail you always end up with multiple
toolbars/buttons/etc. when multiple WordMail items are opened at once.
There's really no way to avoid that with WordMail 2003 or earlier. So you
have to work around that.
First, if you always add your Inspector wrapper Key value to any tags you
create that enables the code to find the specific UI created for that
Inspector among multiple open items. The custom UI you created was added to
Word as part of any CustomizationContext and will remain in the template
used for CustomizationContext unless explicitly deleted, since Word doesn't
honor the Temporary argument used when creating UI.
In addition you have the problem of being prompted when Word closes that
something changed in Normal.dot if the user has Word set to prompt for that
on closing.
I always set up a Word event handler in each Inspector wrapper. I
instantiate that from Inspector.WordEditor, which is the Word.Document
object. From there I can get WordEditor.Parent, the Word application object.
That lets me use wordApp.CustomizationContext.Saved = True every time I make
any changes to any Word UI (add, delete, change visibility, change enabled
state, etc.). That prevents the prompt to save.
That also lets me handle the Word.WindowActivate() event. When that fires
when a WordMail item gets activation I check for wn.EnvelopeVisible. If True
that means the window is a WordMail window, if False it's not. If it's not a
WordMail window (user opened a document from the file system or a new
document) I set the visibility of any UI I created to False so the user
doesn't see it in that document.
If it is a WordMail window I iterate the CommandBars collection of the
document and find all instances of my UI. If the tag in the UI object ends
with the Key value for that Inspector I enable and make visible that UI. If
it's from some other WordMail document (a different Key value) I make that
UI element invisible and disabled so the user doesn't see it even in the
View, Toolbars menu.
Then when the item is closing I get the UI I created and delete it so it
doesn't persist.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
"Steffen Grellmann" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Ken,
>
> in the meantime I've taken a closer look at the Inspector Wrapper
> example from your website and adapted it for using in VSTO 2005 in
> conjunction with OL 2003. So I've got rid of the multiple clicks. As
> you may remember I'm trying to add a button to a WordMail commandbar.
> This is working fine so far with one exception: If multiple drafts of
> a new mail are opened, the button is added multiple times.
>
> I thought I could fix this behaviour with a closer look at the
> CreateButtons and CreateMenus procedures in your Inspector Wrapper
> code, but I'm a bit confused about setting m_obj = Nothing if WordMail
> is true. What has been your initial idea when checking for WordMail?
>
> Beside that, I'm not clear about the UnInitHandler in objInsp_Close
> because I can't find an UnInitHandler Sub or Function in your code.
> What should this UnInitHandler do?
>
> Kind regards,
>
> Steffen