I have an application which embeds an instance of word 2007 inside of it. Everything works fine except until I open a fresh instance of word 2007 from the start menu. Instead of opening a new instance of word it finds my instance and loads a blank document inside of it. Is there a registry setting that will force word to always start in a new instance or some way to mark my instance of word so that it doesn't get hijacked? Anyone else out there seen this happen?

I seem to have found my own solution and I want to post it. I have seen this issue discussed on other threads and have yet to see a solution. Here is what worked for me (I'm using Visual Studio 2003 and Word 2007). I put an event handler on my instance of Word.Application which listens for the Open_Document event. I also added a special character sequence to the name of any document I create inside of my application. Now any time the open document event is fired it checks for that character sequence. If it is there it allows the document to open inside my instance of word. If it is not there then the application stores the path and file name of the document, closes the document, then spawns a new instance of word and passes the file path to the new instance. You may see a graphical hiccup where the document appears in your application for a second prior to closing but in experimentation on my machine this was rare and brief.

If Doc.Name.ToLower.IndexOf("nbdr") < 0 Then
                oWordApp.ActiveDocument.Close()
                Dim newWordApp As New Word.Application
                Doc = newWordApp.Documents.Open(path & "\" & file)
                newWordApp.Visible = True
                ' BDWordWindow1.RaiseBillOpenedEvent()
   End If

I have an application which embeds an instance of word 2007 inside of it. Everything works fine except until I open a fresh instance of word 2007 from the start menu. Instead of opening a new instance of word it finds my instance and loads a blank document inside of it. Is there a registry setting that will force word to always start in a new instance or some way to mark my instance of word so that it doesn't get hijacked? Anyone else out there seen this happen?

commented: Great Follow Up! +10
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.