title: C# to close Microsoft WORD document that was created but was never saved
body: <p>My following code creates a WORD document that my <code>C#</code> code can edit. But if an error occurs I want to close the doc in the <code>catch</code> block of <code>try-catch</code> statement. Question: How can we programmatically close it. I know <a href="https://docs.microsoft.com/en-us/visualstudio/vsto/how-to-programmatically-close-documents?view=vs-2019" rel="nofollow noreferrer">how to close it</a> when a document is saved on a hard disk and you know the path of the doc?</p>
  
  <pre><code>Microsoft.Office.Interop.Word.Application myWordApp = Globals.ThisAddIn.Application
  Microsoft.Office.Interop.Word.Document tempDoc = myWordApp.Documents.Add(Visible: false);
  </code></pre>