Detect difference between close and quit in word RRS feed

  • Question

  • Hello,

    From within a word addin, is it possible to detect the difference between a document being closed and the whole application being quit?

    I have a need to quickly create, save and then close again a new document on either a close or a quit event. This works fine if I put it in the Application.DocumentBeforeClose event, however if the user clicked to quit the entire application it will only close the document, not quit word. Presumably this is due to be creating a new document which cancels the quit command.

    I therefore need a way to detect whether the user has clicked quit or close, and then quit the application if this was their action.

    Any help would be greatly appreciated.


    Thursday, October 9, 2014 11:16 AM

All replies

  • Hello Edward,

    The Word object model provides the Quit event of the Application class. It is fired when the user exits Microsoft Word. Also you may find the Close event of the Document class helpful. It is fired when a document is closed.

    Thursday, October 9, 2014 12:34 PM
  • Hi Eugene,

    Unfortunately, the Quit event does not get fired. In my before close event I currently have the following code (I realise at this moment this code is pointless):

                Document a = Application.Documents.Add();

    When the user clicks the X to quit word completely this event gets fired, which I want, but then doesn't quit word completely as the quit event doesn't get fired.

    I need to detect within the before close event whether the call came from a completely application quit or just a close document event.
    • Edited by EdwardAB Thursday, October 9, 2014 3:09 PM
    Thursday, October 9, 2014 3:08 PM
  • Edward,

    How and where do you subscribe to the Close event of the Document class?

    Friday, October 10, 2014 8:34 AM