Add-in Menu Doesn't Unload Cleanly when Word is Shut Down

C

Christine

My load-on-demand add-in written in VisualBasic.NET for Word 2003 loads and
unloads cleanly as long as I use the COM Add-in command of the Tools menu to
load and unload it. Consistent with this, the menu associated with my add-in
displays and disappears cleanly when the add-in is loaded and unloaded using
the Tools menu, and, in that situation, when the menu is visible it works.
However, when Word is closed with the add-in in place, then re-started, then
(1) the add-in information is inconsistent; when Word is re-opened, the
add-in's LoadBehavor is 9, "loaded", even though OnConnection was not called;
(2) because, OnConnection was not invoked, the code to build the menu was
not executed,
(3) the menu is visible, apparently a "leftover" from a less-than-clean exit
on the prior shutdown of WOrd. I coded the work-around in OnDisconnection for
the bug described in KBKB230876 - i.e., I re-acquire the menu reference,
assuming that the previous reference has been invalidated before.

In the OnDisconnection code, if I invoke MainMenuBar.FindControl("My Menu
Name"), a value is returned (though the menu doesn't seem to get deleted in
this situation, as it is when the add-in is unloaded normally). However, when
Word is re-started, and the non-functional menu is displayed,
MainMenuBar.FindControl("My Menu Name") does not return a value, as if the
menu is being displayed but is not really included as a CommandBarControl
object included by the Main Menu Bar.

Can anyone shed some light regarding what is going on here, and, in
particular, about a work-around? I can tell users of the add-in to unload
using the Tools menu, but would prefer to provide software that behaves
properly in this situation.

- Christine
 
S

Satin

Hi Christine
i faced somewhat similar problem.. for workaround, i now first find the
custom menu on connect and delete it and then reload it . it works for me
!! no need to ask the users :)
satin
 
C

Christine

Well, I do locate and replace the custom menu on connection, and that works.

The problem I'm discussing here occurs when Word does not call OnConnection,
and the OnDisconnection code did not work as planned, so there's a
non-functional menu sitting there. I don't think Word is supposed to call
OnConnection because this is a load-on-demand add-in, but in general Word
seems to be confused about whether the add-in is loaded because the
LoadBehavior in the add-in entry in the registry is 9 (connected) even though
OnConnection was not called.
 

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