none
VSTO Document Events Not Firing when Document With Macro's opened RRS feed

  • Question

  • Hi all,

    I have a VSTO project running on Office 2010 which for the most part seems to be working correctly. However I have a DocumentOpen event registered with the following code:

    this.Application.DocumentOpen +=
                    new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentOpenEventHandler(Application_DocumentOpen);

    This works fine most of the time, but when I open a document containing Macros I get a security prompt and until I allow the Macro this event (and certain others such as Ribbon validation) does not fire. If I don't allow the Macro the events never fire.

    The Addin Startup also fires the Application_DocumentOpen method if it is started with a document,  and this works correctly regardless of Macros being disabled or not. This leads to the odd situation that if both Word and the document are opened with a double-click on the document, the Application_DocumentOpen fires, but if the document is opened after Word is opened it doesn't fire.

    I see a similar issue has been raised in 2007 here, but I can't believe that this is the only solution and if so, how it has been allowed to be carried forward to 2010. If this is the case then I believe this is a fundamental issue with the VSTO security model, which will in many cases render the DocumentOpen event useless.

    Can anyone offer any further insight into this problem please?

    Thursday, June 21, 2012 3:49 PM

Answers

  • Hello C.

    The security model from Office 2003 changed a lot in Office 2007, and tightened even more in Office 2010. You are welcome to submit a design change request through the Web site at

    MSConnect.  https://connect.microsoft.com.  . 


    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    Wednesday, June 27, 2012 6:55 PM
    Moderator

All replies

  • Hi Abbey,

    Thanks for posting in the MSDN Forum.

    Would you please tell me whether your VSTO project is a AddIn or document-level application?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, June 22, 2012 5:31 AM
    Moderator
  • Hi Tom,

    The project is an AddIn project.

    C

    Friday, June 22, 2012 7:40 AM
  • Hi Abbey,

    It's based on my experience that the Application instance need to subscribe the DocumentOpen event when the WINWORD.exe launching. So all will work fine if your macro is in the Word document (in *.docm file), and it will not work if you call it at other place.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 25, 2012 4:48 AM
    Moderator
  • Hi Tom,

    Sorry but this doesn't help me.

    The DocumentOpen event is registered correctly and always fires correctly when a document is opened, unless that document happens to contain a Macro (a totally unrelated Macro) and is untrusted. In this instance (depending upon your security settings) unless you enable the Macro the event does not fire. Unless this can be resolved then it renders the DocumentOpen event largely useless as I can't be sure if a user will open a document with a Macro or not.

    C.

    Monday, June 25, 2012 8:33 AM
  • Hello C.

    The security model from Office 2003 changed a lot in Office 2007, and tightened even more in Office 2010. You are welcome to submit a design change request through the Web site at

    MSConnect.  https://connect.microsoft.com.  . 


    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    Wednesday, June 27, 2012 6:55 PM
    Moderator