none
DocumentOpen event not fired when doc is opend via double click from desktop/explorer RRS feed

  • Question

  • Hi,

    we have a word add-in, which is consuming word events

    and is registering eventhandlers in the Startup method of the add-in like this

               

    Globals.ThisAddIn.Application.DocumentOpen += Application_DocumentOpen;

     

    Globals.ThisAddIn.Application.DocumentBeforeClose += Application_DocumentBeforeClose;

               

    Globals.ThisAddIn.Application.DocumentChange += Application_DocumentChange;

    The Events are fired fine as Long as we open documents from within word.
    When opening the first word document with a double click, the document Change Event is fired, but not the DocumentOpen.

    Why?
    Is there anything we can do to get the document open Event correctly?

    Regards


    • Edited by _Red_Baron_ Wednesday, March 9, 2016 8:02 AM
    Tuesday, March 8, 2016 5:52 PM

Answers

  • Hello Starain,

    thank you very much for your valuable feedback.

    I was assumung, that it is related to the add-in initialization.
    Just for your information: we have the problem in word 2010, 2013 and 2016.
    So nothing changed in between, which is boring and a shame for MS not to fix this in between.

    Now we have to write extra code, which is error prone, as every extra code.
    We fixed it in a similar way to circumvent the issue, without modifying the generated initialization code.

    To explain our fix I describe what we observed how word raises the events

    Opening a document leads to a

    document change event followed by a document open event

    Creating a new document leads to a

    document change event followed by a document new event.

    So the document change event is always before the open/new event.
    Which drives me crazy with your description, because, why do we get the document change event in that case, if normaly the document open event would be triggered later.

    But lets proceed with our fix.

    In case of a double click on a word doc file the document change event is raised, but not the document open event, as described.

    But in this case the add in startup event is triggered immediatly before the document change event.

    So what we do is setting a bool variable in the startup event handler, that we are during initialization phase
    In the document change event handler, we check if we are in initialzation phase.


    If yes, we call the document open event handler by code and reset the bool variable to false.

    This fixes the problem and the need to copy code into the Intialize component code.

    So please MS, fix this.
    It is cumbersome to handle it.

    Best regards
    RB


    • Marked as answer by _Red_Baron_ Wednesday, March 9, 2016 10:10 AM
    • Edited by _Red_Baron_ Wednesday, March 9, 2016 10:18 AM
    Wednesday, March 9, 2016 10:10 AM
  • Hi,

    Yes, for this way, the DocumentOpen event won’t be trigger.

    Since Word 2010, the word startup behavior is changed, VSTO runtime waits for Word to be ready before firing the ThisAddIn_Startup event. And In this scenario by that time the DocumentOpen and WindowActivate events are already fired.

    A related thread:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/3027424c-add3-4935-a822-b517147dbdef/documentopen-and-windowactivate-events-do-not-fire-on-word-2010?forum=vsto

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by _Red_Baron_ Wednesday, March 9, 2016 10:10 AM
    Wednesday, March 9, 2016 9:05 AM
    Moderator

All replies

  • Hi,

    Yes, for this way, the DocumentOpen event won’t be trigger.

    Since Word 2010, the word startup behavior is changed, VSTO runtime waits for Word to be ready before firing the ThisAddIn_Startup event. And In this scenario by that time the DocumentOpen and WindowActivate events are already fired.

    A related thread:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/3027424c-add3-4935-a822-b517147dbdef/documentopen-and-windowactivate-events-do-not-fire-on-word-2010?forum=vsto

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by _Red_Baron_ Wednesday, March 9, 2016 10:10 AM
    Wednesday, March 9, 2016 9:05 AM
    Moderator
  • Hello Starain,

    thank you very much for your valuable feedback.

    I was assumung, that it is related to the add-in initialization.
    Just for your information: we have the problem in word 2010, 2013 and 2016.
    So nothing changed in between, which is boring and a shame for MS not to fix this in between.

    Now we have to write extra code, which is error prone, as every extra code.
    We fixed it in a similar way to circumvent the issue, without modifying the generated initialization code.

    To explain our fix I describe what we observed how word raises the events

    Opening a document leads to a

    document change event followed by a document open event

    Creating a new document leads to a

    document change event followed by a document new event.

    So the document change event is always before the open/new event.
    Which drives me crazy with your description, because, why do we get the document change event in that case, if normaly the document open event would be triggered later.

    But lets proceed with our fix.

    In case of a double click on a word doc file the document change event is raised, but not the document open event, as described.

    But in this case the add in startup event is triggered immediatly before the document change event.

    So what we do is setting a bool variable in the startup event handler, that we are during initialization phase
    In the document change event handler, we check if we are in initialzation phase.


    If yes, we call the document open event handler by code and reset the bool variable to false.

    This fixes the problem and the need to copy code into the Intialize component code.

    So please MS, fix this.
    It is cumbersome to handle it.

    Best regards
    RB


    • Marked as answer by _Red_Baron_ Wednesday, March 9, 2016 10:10 AM
    • Edited by _Red_Baron_ Wednesday, March 9, 2016 10:18 AM
    Wednesday, March 9, 2016 10:10 AM