0
votes

I Opened/Created a new Word document dynamically on FormLoad using:

  • using Word = Microsoft.Office.Interop.Word;
  • oWord = new Word.Application();
  • oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

I have "SAVE BUTTON" that saves the said document using:

  • oDoc.SaveAs(ref filename, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

Then I added the syntax for closing the document on FormClosed using:

  • oDoc.Close(ref oMissing, ref oMissing, ref oMissing);

Scenario: I Ran my program and closed/exit after. Suddenly a "Save as" dialog for the document popped up. I realized that I haven't saved the document because the saving process is in the "SAVE BUTTON".

How can I scape saving the document or automatically choose "cancel" for saving? Any help folks?

2

2 Answers

5
votes

The Close method includes a parameter for whether changes should be saved. Just pass wdDoNotSaveChanges as the first parameter. See the documentation for the Close method for details.

0
votes

Set the property oDoc.Saved to true. Then Word will not prompt to save when the document is closed