none
Create private instance of Word RRS feed

  • Question

  • Hi

    I am automating Word to access its spell checking facility. I am instantiating a new instance with CreateObject("Word.Application"). It is used on a long running basis since the app has numerous areas which are frequently changing and require spell checking so - rather than repeatedly instantiating a new instance of Word multiple times - currently I am opening, and holding a reference to a new instance of word and sharing it with all part of the app which need access to spell checking facilities.

    Unfortunately, if I have my app running and performing spell checking and then manually open a document, say from explorer, the word instance being used, gets re-used by the document I am opening and then things can start to get confusing. For example, when  automating Word 2007, the only way to get a new word, which has just been added to a custom dictionary, recognised by my spell checking facility is to restart the instance of word. This obviously means that if a document has been opened, then it gets closed when I quit the word instance.

    I was wondering if there is a way to effectively create a "private" instance which wouldn't get touched if word was needed in other scenarios - effectively to force a new instance to be created rather than sharing the instance I have created.

    I hope that is sufficiently clear

    Many thx in advance

    Simon


    • Edited by Simon Woods Wednesday, November 14, 2012 6:49 PM Clarification
    Wednesday, November 14, 2012 6:48 PM

Answers

  • Hi Simon

    Word is behaving as it was designed to do and this has been a known issue with Office applications, generally, since "forever". The only possible workaround I know of is described here:
    http://support.microsoft.com/kb/188546

    FWIW, Word 2010 and later tend to start a new instance when a file is accessed via Windows Explorer - which causes all kinds of other issues for those who've relied on it not doing so...


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, November 15, 2012 12:27 PM
    Moderator

All replies

  • Hi Simon,

    Thanks for posting in the MSDN Forum.

    I would recommend you clarify your scenario more detailed. It's based on my understand that you want only one Word instance exists in the issue. Is it right? I suppose you use VB.NET in these issue.

            Dim Procs() As Process
            Dim wdApp As Word.Application
    
            Procs = Process.GetProcessesByName("WINWORD")
            If Procs.Length > 0 Then
                wdApp = CreateObject("Word.Application")
            Else
                wdApp = New Word.Application
            End If

    I hope it can help you.

    Have a good day,

    Tom


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

    Thursday, November 15, 2012 4:50 AM
    Moderator
  • Thx Tom

    Unfortunately the problem is not whether or not to create a new instance, but rather that if a user, whilst using my spell checking app, switches task and  opens a doc from explorer, that newly opened doc uses the same process that I instantiated for spell checking.

    So, for example, if I open task manager when I am running my spell checking app, I can see a single instance of word. If I then  open a document by double clicking on it in explorer, the document opens and word becomes visible, yet in task manager there is still only one instance of word running - so it is being shared now by my spelling app and the newly opened document.

    I suppose another option, if it were possible - would be to see how many "users" there are of that instance of word and if that number>1 then start a new instance in my spell checking app. Would that be possible? 

    Any thoughts? (VB is fine btw)

    EDITED: So I'm wondering whether monitoring the thread count is going to be good enough and starting an instance of word, getting its pid and thread count. If when I access it the thread count has increased, is that good enough to prove that another app is now using my instance and that i need to create a new one?

    Thx again

    S



    • Edited by Simon Woods Thursday, November 15, 2012 8:09 AM More details
    Thursday, November 15, 2012 7:06 AM
  • Hi Simon

    Word is behaving as it was designed to do and this has been a known issue with Office applications, generally, since "forever". The only possible workaround I know of is described here:
    http://support.microsoft.com/kb/188546

    FWIW, Word 2010 and later tend to start a new instance when a file is accessed via Windows Explorer - which causes all kinds of other issues for those who've relied on it not doing so...


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, November 15, 2012 12:27 PM
    Moderator
  • OK. Thx very much Cindy
    Thursday, November 15, 2012 2:20 PM