I need to either disable SaveAs in word or prevent the User from changing the file name.
My application allows the user to create a MailMerge Document using headers I provider for them. This works when the user just simply Saves and exits Word. If the user Saves As, the application locks up.
I’m using Microsoft.Office.Interop.Word.
//MyWordApp & doc is initialized.
MyWordApp.Application.Visible = true;
While(WordIsOpen())//Holds execution here while User is editing in Word
{
}
WordIsOpen Definition:
public bool WordIsOpen()
{
if (MyWordApp.Application.Visible)//Locks up here
{
return true;
}
else
return false;
}
Lock up:
//I have a BeforeSave event that Saves the doc and quits Word
DocumentBeforeSave(Doc, SaveAsUI, Cancel)
{
//Save Doc
MyWordApp.Quit(ref objFalse, ref objNull, ref objNull);//Also, Locks up here
}
I’m not completely sure what ultimately caused this issue. I determined it has something to do with the COM behavior. There is a known bug while using the Word Interop in debug mode. The only way I came across that could potentially resolve this issue is to intercept COM events occurring before or on SaveAs. I did not implement that solution so I do not know what is all involved in that.