need Document Close event handler

  • Thread starter Thread starter Eric Li
  • Start date Start date
E

Eric Li

Hi, Group,

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?

Thanks.


Eric
 
Eric said:
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_DocumentEvents_Event_Close);
}

private void doc_DocumentEvents_Event_Close()
{
MessageBox.Show("Close event");
}

Cheers

Arne Janning
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top