title: Cannot Close Down MS Word From .NET
body: <p>I have the following snippet of code.  It works (opens all the Word documents in a directory and then closes them down)...but it doesn't clean up after itself when I totally exit the program.  </p>
  
  <p>By this I mean that if I look at the TaskManager once I exit the VB.NET application I see the WINWORD.EXE even though it did not exist before I opened the application.</p>
  
  <p>Here's the declarations I have:</p>
  
  <pre><code>Dim WordApp As Microsoft.Office.Interop.Word.Application
  Dim aDoc As Microsoft.Office.Interop.Word.Document
  
  Dim missing As Object = System.Reflection.Missing.Value
  Dim nullobj As Object = System.Reflection.Missing.Value
  
  Dim MYreadOnly As Object = False
  Dim isVisible As Object = False
  </code></pre>
  
  <p>And here's the code:</p>
  
  <pre><code>Private Sub cmdGenerate_Click(sender As System.Object, e As System.EventArgs) Handles cmdGenerateKeywords.Click
  
    Dim xmldoc As New XmlDataDocument()
    Dim xmlnode As XmlNodeList
    Dim i As Integer
    Dim fs As FileStream
  
    WordApp = New Microsoft.Office.Interop.Word.Application
    WordApp.Visible = False
  
    For Each f As FileInfo In New DirectoryInfo(txtFolderName.Text).GetFiles("*.docx")
      ' Open the document that was chosen by the dialog
      aDoc = WordApp.Documents.Open(f.FullName, missing, [MYreadOnly], _
             missing, missing, missing, missing, missing, missing, missing, _
             missing, isVisible)
      'aDoc.Close()
      aDoc = Nothing
    Next
  
    'Close the Word Document
    'aDoc.Close(nullobj, nullobj, nullobj)
    WordApp.Application.Quit()
    WordApp = Nothing
  End Sub
  </code></pre>
  
  <p>As you can tell I've commented and uncommented various statements in regards to closing down Word documents and the Word Application itself.  Nothing I have tried seems to be able to get rid of that pesky WINWORD.EXE</p>
  
  <p>Something seems to have a lock and will not let it close down? Is that it?</p>