none
Word Cannot Save the file because it is already open elsewhere (normal.dotm) RRS feed

  • Question

  • I am working on a Windows 7 / Office 2007 PC.

    If I open a second instance of Word then I cannot call the Quit method without word trying to save normal.dotm.  Further because it its the second instance it shows a dialog "Word Cannot Save the file because it is already open elsewhere"

    I built a test app with only this code.

        Sub Main()
    
            Dim wApp As Word.Application
    
            Dim missing As Object = System.Reflection.Missing.Value
            Dim wNoSave As Object = Word.WdSaveOptions.wdDoNotSaveChanges
    
            wApp = CreateObject("Word.Application")
            wApp.Visible = True
    
            wApp.NormalTemplate.Saved = True
    
            wApp.Quit(wNoSave, missing, missing)
    
            System.Runtime.InteropServices.Marshal.ReleaseComObject(wApp)
    
        End Sub

    If word is already open then the above code will not run without word trying to save normal.dotm again.

    If I open a second instance of word myself manually then word does not complain that it cannot save normal.dotm so what is different in the code.

    I am using VB.net but dont think it would matter if this is VBA or C# it is pretty basic stuff.

    Monday, August 27, 2012 6:46 AM

Answers

  • Hi Cindy again.

    Of course the answer to this problem seems to be to not start a second instance, which I don't want to do anyway.

    For some reason in my testing in the real app I thought I had to start a new instance all the time.  I have now tested the Documents.Add method and I can add my document to an existing instance of word (without stuffing up whatever else is already open).  I can even open it invisible and then close it.  In this case I leave the Quit method alone and do not call it.

    So the answer to my question is don't open a second instance.

    And if you are here reading this ask yourself why do you need to have a second instance of word, it does not appear as though this is intended.

    • Marked as answer by donky73 Monday, August 27, 2012 12:32 PM
    Monday, August 27, 2012 12:32 PM

All replies

  • Hi donky

    <<If I open a second instance of word myself manually then word does not complain that it cannot save normal.dotm so what is different in the code.>>

    How are you opening a second instance yourself, manually? It's important to be aware that Word will show multiple documents in multiple windows but  it will usually be the same instance of Word, not a separate one. Pseudo-SDI is what this is usually called. If an instance of Word is running and you double-click a document in Windows Explorer Word is configured to re-use the running instance, even though the document is displayed in a separate window.

    So it's quite likely that what you're observing as an end-user is not actually a separate instance.

    I am somewhat surprised that the code you show doesn't work, because it does here in a quick test. How about if you use New Word.Application instead of CreateObject?


    Cindy Meister, VSTO/Word MVP

    Monday, August 27, 2012 12:01 PM
    Moderator
  • It's important to be aware that Word will show multiple documents in multiple windows but  it will usually be the same instance of Word, not a separate one.

    I think i saw this in your post or another persons.  You are correct.  If I have a document open and then right click on the Word icon on the task bar and choose "Word 2007" I have 2 word windows but in task manager "WINWORD.EXE" is only running once.

    The above code does generate a second instance of "WINWORD.EXE".

    A second instance of word is also started if I use "Dim wApp As New Word.Application" and not CreateObject.  Word also has the same complaints when the quit method is called.

    Monday, August 27, 2012 12:18 PM
  • Hi Cindy again.

    Of course the answer to this problem seems to be to not start a second instance, which I don't want to do anyway.

    For some reason in my testing in the real app I thought I had to start a new instance all the time.  I have now tested the Documents.Add method and I can add my document to an existing instance of word (without stuffing up whatever else is already open).  I can even open it invisible and then close it.  In this case I leave the Quit method alone and do not call it.

    So the answer to my question is don't open a second instance.

    And if you are here reading this ask yourself why do you need to have a second instance of word, it does not appear as though this is intended.

    • Marked as answer by donky73 Monday, August 27, 2012 12:32 PM
    Monday, August 27, 2012 12:32 PM
  • Hi donky

    Hah! I didn't want to ask that because I assumed you knew why you were starting a second instance. It's a relief to know that you actually did not, so there was an easy solution :-)

    I was debating on whether to get into renaming Normal.dotm and all kinds of other "nasties" - glad I won't have to!


    Cindy Meister, VSTO/Word MVP

    Monday, August 27, 2012 1:01 PM
    Moderator
  • Thank you Cindy for picking up the thread.  Not only was my question strange because my starting code should have worked, I don't even know why I was going down this path.

    For some reason Documents.Add was removing existing documents.  Obviously now it is not and should not.

    I have spent hours trying to work this out.

    Thank you again.


    • Edited by donky73 Monday, August 27, 2012 1:23 PM spelling
    Monday, August 27, 2012 1:09 PM