I have a windows form with Office Word inside it. I am opening word documents programmatically with code (_wd is of type Microsoft.Office.Interop.Word.ApplicationClass - I am using VS 2012, .NET 4.5, Office 2007):
public void LoadComponent(string path)
{
if (_wd.Documents.Count != 0) _wd.ActiveDocument.Close();
_wd.Documents.Add(ref path);
}
My problem comes when I want to save active document. I don't want save prompt to appear - here's what I've tried, and couldn't cancel the prompt dialog:
_wd.ActiveDocument.Saved = true;
_wd.ActiveDocument.Save();
If I try with:
_wd.ActiveDocument.SaveAs(_filePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
I receive Exception: 'Word cannot save this file because it is already open elsewhere.' - but it is opened only inside my application, nowhere else. How to save Word document which is opened without save prompt dialog programmatically? Interesting thing is that even if I try to save the document by pressing 'save' button I got save prompt dialog -> like the document was not created before on disc. But, the document is opened from disc, only it is opened programmatically. If I open the document with Word and then press 'save' I never got save prompt dialog.