I've found that with WordMail that I have to re-instantiate my
button/toolbar/menu objects each time I want to access their properties,
otherwise I get weird automation errors or errors that the property/method
doesn't exist for that object. Even in a Click event for a button, if I want
to change button.State or some other property like that or alter the image
for the button I get that error in Click. So I've gotten in the habit of
just getting a fresh reference each time I want to access a property even
those like Enabled or Visible.
With Word itself I have less experience, although I've done some Word addins
and some that have to co-exist with Outlook addins. I use the DocumentOpen
event to let me know a new Document was opened and to add UI for that. I
release the UI I created in DocumentBeforeClose and double-check that all UI
is released in OnDisconnection.
I've also found that unlike UI added to an Outlook Explorer or an Outlook
editor Inspector that Word doesn't really honor the Temporary = true
argument, that UI persists wherever it was created in the
CustomizationContext for Word. So I set CustomizationContext.Saved = true
after each time I change, add or remove something in the UI, even just a
visibility or enabled change.
I also use a technique of creating a unique Tag property for each piece of
UI that I create. I use an app specific GUID concatenated with a string
specific to that UI piece ("button1") plus a Key value for that
Inspector/Explorer. The Key is incremented for each call so it's unique for
that session.
I then check the Tags of each object I find when I iterate the
Inspector.CommandBars collection looking for UI that isn't BuiltIn = true.
If it has a partial match (GUID + UI piece are equal but Key is different) I
set that CommandBar invisible and disabled so it's not visible either in the
WordMail item or any open Word docs. I do that in WindowActivate. That way I
can manage UI for multiple open Inspectors and documents and only the
appropriate UI shows up in each and each can have a unique set of settings
without affecting any other.
As far as thanks or some nomination for something, I've been recognized as
an Outlook MVP, which is honor enough for me. I learn as much as I help in
the newsgroups, so that and the satisfaction of helping out are enough