none
Document Close Event RRS feed

  • Question

  • Usually close event is not associated with Microsoft.Office.Interop.Word. but are readily available with Microsoft.Office.Interop.Word.DocumentClass. So I had to cast first to second and subscribe for the event. So this is what I did in order to capture Document Close event

    OnStartupComplete method I wrote this

    public void OnStartupComplete(ref System.Array custom)
    {
         oWord = (MSWord.Application)applicationObject;
         oWord.Visible = true;
    
         Microsoft.Office.Interop.Word._Application appWord = null;
         Microsoft.Office.Interop.Word._Document docWord = null;
         Microsoft.Office.Interop.Word.DocumentClass cls = docWord as Microsoft.Office.Interop.Word.DocumentClass;
    
         ribbon.InvalidateControl("ODTConvertor");
         oWord.DocumentChange += new MSWord.ApplicationEvents4_DocumentChangeEventHandler(oWord_DocumentChange);
         cls.DocumentEvents_Event_Close += new MSWord.DocumentEvents_CloseEventHandler(cls_DocumentEvents_Event_Close);
    }
    
    void cls_DocumentEvents_Event_Close()
    {
         MessageBox.Show("Document Close Event");
    }

    But despite all this effort the close event is not getting captured :(

    Adeel

    Friday, August 3, 2012 5:18 AM

Answers

  • I should have explained in your other threads: There are document (level) events and application (level) events. You could make code run at the point of closing by using either.

    Somewhat confusingly, the document level event is 'BeforeSave'. You need a specific instance of a document to use that; you could hook it every time a new document is opened.

    Probably better for you would be to use the application level event, 'DocumentBeforeSave'.

    • Edited by JosephFox Friday, August 3, 2012 11:03 AM
    • Marked as answer by maverick786us Friday, August 3, 2012 11:40 AM
    Friday, August 3, 2012 11:02 AM