How to close a word document

vb.net, vb6, visual-studio

Solution

Perhaps, you want to close the Word app at the end? Try this:

AppWord.Quit

Problem

When I run this application, the document opens fine but it doesn't close and leaves the document open. How can I close the word doc properly? ``` Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim AppWord = CreateObject("Word.Application") Dim WordDoc = CreateObject("Word.Document") Dim filename As String Dim result As String filename = "C:\Users\Business\Desktop\Test.docx" WordDoc = AppWord.Documents.Open(filename) txtFileContents.Text = WordDoc.Content.Text WordDoc.Close() End Sub ```

Original source