none
Deny documents to open in a vsto created application RRS feed

  • Question

  • Hello,

    I´m creating a new instance of Word through vsto and open a document. After that, some VBA-macros are running and the document gets closed. If the user opens a word-document with a double click, while the vsto created application is running in background (Visible and ScreenUpdating false), the double clicked document gets opened in this Word instance instead of a new one. This causes the macro to crash or run over the wrong document.

    Is there any way to deny a word-document to open in an own vsto created wordapplication or force it to open in a new word instance?

    Thanks for your help.

    Best regards,

    Marcel

    Friday, June 26, 2015 10:37 AM

Answers

All replies

  • Hello Marcel ,

    > I´m creating a new instance of Word through vsto

    Why do you need to create a new Word instance from a VSTO based add-in? Do you automate Word or develop an add-in for Word?

    What exactly do you need to implement? Most probably there is a better way for implementing your task. For example, you may consider using the Open XML SDK for assembling open XML documents (.docx). See Welcome to the Open XML SDK 2.5 for Office for more information.

    By default Word the same Word process is used for opening documents. You may pass a command line parameter (command line switch) to force Word open documents in new processes.  See How to use startup command-line switches to start Word 2010, Word 2007, Word 2003, Word 2002, and Word 2000 .

    Note, you can add "/w" command line parameter to the windows registry at HKEY_CLASSES_ROOT\Word.Document.12\shell\Open\command where 12 stands for Office (Word 2010) version. You can read more about that on the Force Word to start each document in separate process forum thread.

    Friday, June 26, 2015 11:41 AM
  • Hello Eugene,

    Why do you need to create a new Word instance from a VSTO based add-in? Do you automate Word or develop an add-in for Word? What exactly do you need to implement? Most probably there is a better way for implementing your task. For example, you may consider using the Open XML SDK for assembling open XML documents (.docx).

    I have to automate Word, because im running some VBA-marcros, doing some replacements using the Open XML SDK and save the output file as .doc (Word 2003).

    Note, you can add "/w" command line parameter to the windows registry at HKEY_CLASSES_ROOT\Word.Document.12\shell\Open\command where 12 stands for Office (Word 2010) version.

    Thanks for your help, this worked for me.

    Best regards,

    Marcel

    Friday, June 26, 2015 1:06 PM
  • Hi Marcel

    <<I´m creating a new instance of Word through vsto >>

    Could you please be more specific, here? I realize Eugene has given you an answer, but I think your question is in the wrong forum amd I'd like to move it to the more appropriate one. VSTO is a specific technology that runs from within the Office application. So "creating a new instance of Word" is not something we do in VSTO programming. Do you mean, instead, that you're using the "interop", such as a Windows Form?


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, June 26, 2015 4:25 PM
    Moderator
  • Hi Cindy,

    maybe this is the wrong forum. I don´t use VSTO within an Office application. I´ve got a WPF-Application that is running some Code like that:

            private void Example(MemoryStream stream, string templatePath, string outputPath)
            {
                var instance = new Application();
    
                var doc = instance.Documents.Open(templatePath);
    
                instance.ActiveDocument.Range().InsertXML(new OpcToFlatConverter().OpcToFlat(stream).ToString());
    
                instance.Run("SomeMacro.Start");
    
                instance.ActiveDocument.SaveAs2(outputPath, WdSaveFormat.wdFormatDocument);
    	
            }

    Best regards,

    Marcel

    Monday, June 29, 2015 7:48 AM
  • Thank you, Marcel :-) I'll move this to the Word for Developers forum.

    Cindy Meister, VSTO/Word MVP, my blog


    Monday, June 29, 2015 5:17 PM
    Moderator