word add-in not working when opening a document

T

Toni

I have made a word add-in with IDTExtensibility2 interface. When I start
word 2003 from start menu everything works fine. But when I open a "old"
document it doesn´t.
The toolbar appears but with no function. Seems like word or xp remove
assemblies when opening a document or something. Tried to save document with
the working add-in, but when I opened it again same thing happened.
 
B

Brian

I have a very similiar problem. I've been bangin my head against a wall on it
for 4 days now. I have a .NET COM Interop Addin written in C#. When it loads,
it adds a CommandBarPopup and two CommandBarButtons's to the main 'Menu Bar'.
One allows you to open a document from our in-house doc-repository which
lives in Access. The buttons work fine as far as fireing their respective
events, etc. But, once you say "open document" and, that actually happens,
the menu no longer works. My first thought was that once the document is
loaded as a "new" document, a new window objet was being created and the
event handler registrations where being wiped out. However, I tested that
theory by hooking into to the document open event. Once that fires I take the
newly opened document, grab it's Application interface and to that, re-wire
the event handlers. Still nothing. Here is the code I use to activate the
document:


public void ActivateDocument(Document slDoc, ServerConnection psc)
{


try
{
Document slDocDeep = psc.DocumentManager.getDocument(slDoc.id);


FileStream fs = new FileStream(slDocDeep.filename, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(slDocDeep.document, 0, slDocDeep.document.Length);
bw.Flush();
bw.Close();
fs.Close(); // Already done by bw?

object missing = Type.Missing;
object filepath = Path.GetFullPath(slDoc.filename);
wdDoc = wordApp.Documents.Open(ref filepath,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing);

// Lets try re-wiring the event handlers...
// if(menuBar == null)
// menuBar = wdDoc.Application.CommandBars["Menu Bar"];
// foreach (CommandBarControl menuItem in menuBar.Controls)
// {
// if (menuItem.Caption == MENU_ITEM_DOCMGRMENU)
// {
// popup = (CommandBarPopup)menuItem;
// foreach (CommandBarControl cbc in popup.Controls)
// {
// try
// {
// CommandBarButton bn = (CommandBarButton)cbc;
// if(bn.Caption == MENU_ITEM_SEND_TO_DOCMGR)
// bn.Click += new
_CommandBarButtonEvents_ClickEventHandler(bnSendToDocMgr_Click);
// else if (bn.Caption == MENU_ITEM_OPEN_FROM_DOCMGR)
// bn.Click += new
_CommandBarButtonEvents_ClickEventHandler(bnOpenFromDocMgr_Click);
// else
// MessageBox.Show("Unable to wire it up: " + bn.Caption);
// }
// catch(Exception ex)
// {
// MessageBox.Show(ex.Message);
// }
// }
// }
// }

//wdDoc.Activate();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
// try
// {
// if (wdDoc != null)
// while(Marshal.ReleaseComObject(wdDoc) > 0);
// }
// catch(Exception ex)
// {
// MessageBox.Show(ex.Message);
// }
}
}

once the call to wordApp.Documents.Open() occurs and the document is loaded,
all menu activity for the menu I added seems to be ignored. Any ideas?

Thank you,

Brian
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?QnJpYW4=?=,
once the call to wordApp.Documents.Open() occurs and the document is loaded,
all menu activity for the menu I added seems to be ignored. Any ideas?
did you assign unique values to the Tag properties of the CommandBar controls?
Without that, one gets the behavior you describe.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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