Launch Word and check if the document is closed

we need for our school project a way to run an instance of a word and track if the document was closed. Does the COM api from doens't have an event for this, are there other ways to do this?

Currently we use COM api from the word, but everything else will be fine. We program in C #.

+5
source share
2 answers

If you use the Microsoft.Office.Interop.Word library, there is an event that you can also subscribe:

Microsoft.Office.Interop.Word.Application wordApp =
    new Microsoft.Office.Interop.Word.Application();
wordApp.DocumentBeforeClose +=
    new ApplicationEvents4_DocumentBeforeCloseEventHandler(
        wordApp_DocumentBeforeClose);

...

private void wordApp_DocumentBeforeClose(Document Doc, ref bool Cancel)
{
    // Do your thing
}

Edit:

== > . , DocumentBeforeClose :

  • , . == > , .

, , . .

+2

winword, , , .

, .

var info = Process.GetProcessesByName("winword").FirstOrDefault();

Process.MainWindowTitle

Process.Exited

+2

All Articles