none
Double Klicking a File does not fire DocumentOpen event in Word RRS feed

  • Question

  • Hi.

    I have a VSTO Word Com-Addin and I do some action in the document open event. However it seems it is not fired if I open it be double klicking in explorer for examlpe. It is only fired when I use open from inside of word.

    Is this some VSTO bug or what can I do?

    Office is 2010 Ultimate
    Addin is a VSTO 2007 Word Addin
    Visual Studio is 2010 Ultimate SP1

    Kind regarts,
    TK



    Monday, July 11, 2011 9:15 AM

Answers

  • Hi Torsten

    <<What I do is I change the view to hide comment markups because Word is using the setting the document was saved with. (I guess there is no built in option in word?)>>

    No, there's no way to change this, but I think you'll manage OK for this with what you've got...

    <<I thought word is starting, loads my addin and then opens the document.>>

    Not necessarily, although it might appear that way. It's very difficult to know what's actually going on, in what order :-) VBA would probably be able to figure it out best, but there's no guarantee things will occur in exactly the same order every time Word starts.

    <<What is working is DocumentChanged, this event is called. Perhaps I can use that. I guess there is no unique identifier for a document which I can use to track the state of a document? For example I could store the information if I have already done my action for a document.>>

    The unique identifier for a document is its FullName (path plus file name). You could also write information into something in the document. One possibility would be a Document VARIABLE object (Document.Variables.Item). That's place where you can store string values and is available in all versions of Word (and I do mean all). Another possibility would be  to put a Custom XML Part (word 2007, 2010) in the document and write information to that. You could even keep a log of what you've done when, if that would help you.


    Cindy Meister, VSTO/Word MVP
    Monday, July 11, 2011 11:53 AM
    Moderator
  • Hi Torsten,

    Your issue confirms an issue that a colleague reported to me about a problem on 2010 with our add-in not setting up properly when the user opens a file directly from Windows Explorer.

    A similar (but slightly different because template are involved and not com add-ins) problem occurred on Word for the Mac 2011 using the VBA Document_Open and Document_New events. The workaround there was to add an AutoNew and AutoOpen routine that used a wait method which would allow Word to fully load before executing the custom template's Document_New or Document_Open event.

    So I think as Cindy said, there might be first time check of a doc variable to workaround this Word 2010 issue but I haven't gotten that one near the top of my critical to do list yet.

    Yours in co-misery :-)


    Kind Regards, Rich ... http://greatcirclelearning.com
    Monday, July 11, 2011 4:45 PM

All replies

  • Hello Torsten,

    This is the way Word works.


    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader
    Monday, July 11, 2011 10:59 AM
  • Hi Torsten

    I believe this is a new behavior with Office 2010. I sure can't understand why MS changed the default behavior when double-click Word documents in Windows Explorer, but now the default installation behavior is for this to start a new instance of Word, rather than open the document in an existing instance.

    So your Add-in isn't catching the Open event because it's not firing in the same instance of Word.

    And with the new instance, your add-in probably isn't loaded and ready for the event to fire.

    You're going to have to build something into the Startup event do allow for this new behavior. Since the user could conceivably unload / reload your add-in at any time during a Word session it probably doesn't make sense to check the number of documents and/or the document name and rely on that to make the assumption that you're dealing with a newly opened document.

    It might make some sense to pick up the WinWord process and check the start time, compared to the "current time" and, if these are within a certain number of seconds, it would be safe to make that assumption?


    Cindy Meister, VSTO/Word MVP
    Monday, July 11, 2011 11:07 AM
    Moderator
  • I thought word is starting, loads my addin and then opens the document.

    What is working is DocumentChanged, this event is called. Perhaps I can use that. I guess there is no unique identifier for a document which I can use to track the state of a document? For example I could store the information if I have already done my action for a document.

    What I do is I change the view to hide comment markups because Word is using the setting the document was saved with. (I guess there is no built in option in word?)

    Monday, July 11, 2011 11:15 AM
  • Hi Torsten

    <<What I do is I change the view to hide comment markups because Word is using the setting the document was saved with. (I guess there is no built in option in word?)>>

    No, there's no way to change this, but I think you'll manage OK for this with what you've got...

    <<I thought word is starting, loads my addin and then opens the document.>>

    Not necessarily, although it might appear that way. It's very difficult to know what's actually going on, in what order :-) VBA would probably be able to figure it out best, but there's no guarantee things will occur in exactly the same order every time Word starts.

    <<What is working is DocumentChanged, this event is called. Perhaps I can use that. I guess there is no unique identifier for a document which I can use to track the state of a document? For example I could store the information if I have already done my action for a document.>>

    The unique identifier for a document is its FullName (path plus file name). You could also write information into something in the document. One possibility would be a Document VARIABLE object (Document.Variables.Item). That's place where you can store string values and is available in all versions of Word (and I do mean all). Another possibility would be  to put a Custom XML Part (word 2007, 2010) in the document and write information to that. You could even keep a log of what you've done when, if that would help you.


    Cindy Meister, VSTO/Word MVP
    Monday, July 11, 2011 11:53 AM
    Moderator
  • Hi Torsten,

    Does this occur when an instance of Word is already open and the user decides to double click a file from Windows Explorer or does it only happen when there isn't an existing instance of Word running?

     


    Kind Regards, Rich ... http://greatcirclelearning.com
    Monday, July 11, 2011 12:26 PM
  • Hi Rich,

    if I have an opened instance of word everything is working fine.

    I have added some messagebox calls into the startup of my event and what I noticed is, that the addin is loaded after the document is already opened. So thats the reason why the addin can't handle the open event.

    Kind regards,
    TK

    Monday, July 11, 2011 3:56 PM
  • Thanks for your tips Cindy.

    Monday, July 11, 2011 3:56 PM
  • Hi Torsten,

    Your issue confirms an issue that a colleague reported to me about a problem on 2010 with our add-in not setting up properly when the user opens a file directly from Windows Explorer.

    A similar (but slightly different because template are involved and not com add-ins) problem occurred on Word for the Mac 2011 using the VBA Document_Open and Document_New events. The workaround there was to add an AutoNew and AutoOpen routine that used a wait method which would allow Word to fully load before executing the custom template's Document_New or Document_Open event.

    So I think as Cindy said, there might be first time check of a doc variable to workaround this Word 2010 issue but I haven't gotten that one near the top of my critical to do list yet.

    Yours in co-misery :-)


    Kind Regards, Rich ... http://greatcirclelearning.com
    Monday, July 11, 2011 4:45 PM