Word 2000, DocumentBeforeClose event only firing once...

A

AP

Hi,

In .NET I create an instance of the Word.Application class, open a document,
then add a DocumentBeforeClose event handler using the word COM object. I do
this twice because I want to open 2 documents. I close one document and the
DocumentBeforeClose event fires. I then close the second document and the
event does not fire. Is this a bug? Workaround?

Thanks,

Adam
 
A

AP

I have accidentaly found a solution. My original code that created a
Word.Application class instance looked like this:

private Word.ApplicationClass GetWordInstance() {
Word.ApplicationClass wa = new Word.ApplicationClass();




return wa;

}

I found if I changed my code so I kept a handle on the instance like so:

private Word.ApplicationClass myWa;

private Word.ApplicationClass GetWordInstance() {

Word.ApplicationClass wa = new Word.ApplicationClass();

myWa = wa;

return myWa;

}

then the event gets fired the second time. In theory, these should be doing
exactly the same thing. If anyone could shed some light on why this works I
would really appreciate it.

Thanks,

Adam
 
A

AP

I have since found that the below is not true and it still fires
inconsistently. What I am now trying to do is add the event listener to word
itself (using VBA) and have this VBA code call a method on an instance of a
class in my .NET application. The problem is that I need to pass this object
instance to word, and then have word call a method on it. I know how to call
..NET methods from word, but I am having trouble working out how to pass an
object to word. If anyone can help that would be great.

Thanks,

Adam
 

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