Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

where is document close event handler

185 views
Skip to first unread message

Eric Li

unread,
May 27, 2004, 8:23:51 PM5/27/04
to
Hi, Group,

I am using C# program (not addin, just EXE) to launch a Word document in
Word 2003. My C# program
will be sitting on "top most" while document opened. I would like to hook up
an event when Word document has been closed (not Word application), my
program will be closed automatically too.

I can't find the "Close" event in ActiveDocument. There are events for "New"
and "Open". Where is event handler for document close?

Thanks.


Eric


Jezebel

unread,
May 27, 2004, 8:29:31 PM5/27/04
to
There isn't one. Nearest is DocumentBeforeClose -- unfortunately the user
can cancel the close after the event. Another approach is to use the
WindowSelectionChange event: if the document is closed the selected window
necessarily changes, so you can check at this point if your document is no
longer open.


"Eric Li" <ericl...@nospam.hotmail.com> wrote in message
news:OeSsslE...@TK2MSFTNGP11.phx.gbl...

Eric Li

unread,
May 27, 2004, 8:59:19 PM5/27/04
to

Hi, Jezebel,

Thanks for your repley. I will try it.

However, if user has two Word documents, switching document will fire up
"WindowSelectionChange" event too, and my EXE will be closed. That's not I
want. How do I know the event is called by document closed or by document
switched? Do you have a way to know?

Thanks.


Eric


"Jezebel" <dwa...@heaven.com.kr> wrote in message
news:OYovZrE...@TK2MSFTNGP10.phx.gbl...

Jezebel

unread,
May 28, 2004, 3:34:01 AM5/28/04
to
I wasn't thinking straight on this. The Word application object doesn't
provide a document close event, but the document object does. If your app
can keep a withevents reference to the document object, then that solves
your problem.

Failing that, you can use the app events (not WindowSelectionChange, my
mistake) but WindowActivate. When fired, you iterate Word's Documents
collection to see if your document is still in it.


"Eric Li" <ericl...@nospam.hotmail.com> wrote in message

news:OX8Gg5ER...@tk2msftngp13.phx.gbl...

Eric Li

unread,
May 28, 2004, 5:21:21 PM5/28/04
to
Thanks for your tips.

Actually my case is kind of complicated. I tried to use
"DocumentClass_DocumentEvents_Event_Close" for Close Event. But, if I close
my EXE in Close Event, my EXE will be getting an error. The reason why is
that my EXE will try to read this document into memory again and upload it
to server before closing itself. Since Close Event is not releasing the
document yet, my EXE can't reload the document.

Finally I figured it out by using the following solution:

1. Fire up Close Event when user clicks "X" on document.
2. In Close Event, I launch a Threading. This threading will check the
document that is holding by Word.
3. The Threading will keep checking the status of document until Word
release the document.
4. My EXE will upload the document to server once Word release the document
5. Close my EXE.

Thanks for your help.


Eric


"Jezebel" <dwa...@heaven.com.kr> wrote in message

news:e4oXsYIR...@TK2MSFTNGP11.phx.gbl...

0 new messages