Eric Li wrote:
I am using C# program to launch a Word document in Word 2003. My C# program
will be sitting on "top most" while document opened. I would like to hook up
an event when Word document has been closed (not Word application), my
program will be closed automatically too.
I can't find the "Close" event in ActiveDocument. There are events for "New"
and "Open". How do I create event handler for document closed?
Hi Eric,
the DocumentClass offers a DocumentEvents_Event_Close. The following
code works for me (Word 2003 and PIAs installed):
private void button1_Click(object sender, System.EventArgs e)
{
ApplicationClass app = new ApplicationClass();
object miss = System.Type.Missing;
DocumentClass doc = (DocumentClass) app.Documents.Add(ref miss, ref
miss, ref miss, ref miss);
app.Visible = true;
doc.DocumentEvents_Event_Close +=new
DocumentEvents_CloseEventHandler(doc_DocumentEvent s_Event_Close);
}
private void doc_DocumentEvents_Event_Close()
{
MessageBox.Show("Close event");
}
Cheers
Arne Janning