kobus

kobus

  • NA
  • 1
  • 0

Can events be hooked to MS Word?

Apr 10 2006 2:45 AM

I want to open a MS Word document using C# code.

 

[code]

Word.ApplicationClass WordApp = new Word.ApplicationClass();

 

// Use the open file dialog to choose a word document 

if (this.openFileDialog1.ShowDialog() == DialogResult.OK) 

{

object fileName = openFileDialog1.FileName;

      object readOnly = false;      

      object isVisible = true;

                 

//Here is the way to handle parameters you don't care about in .NET     

      object missing = System.Reflection.Missing.Value;

                 

      //Make word visible, so you can see what's happening       

      WordApp.Visible = true;

                 

      //Open the document that was chosen by the dialog     

      Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing,ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);

                 

      //Activate the document so it shows up in front       

      aDoc.Activate();

}

[/code]

 

This works fine and it opens the document in MS Word separate from the C# application. Is there a way of hooking an event to the document object (aDoc) so that when the word document is closed the C# application can react to the event?


Thanks
Kobus