From Silverlight 4, it's pretty easy to start Word and let the user do something:
dynamic word = System.Runtime.InteropServices.Automation.CreateObject("Word.Application");
word.Visible = true;
word.Documents.Open("test.doc");
MS Word exposes a Quit event[1]. I'd like to handle this event, but for the life of me I can't figure out how. I tried to do this:
public delegate void WordQuitEventHandler(object sender, ref bool cancel);
public event WordQuitEventHandler OnQuit;
private void WordOnQuit(dynamic sender, ref bool cancel)
{
if (OnQuit != null)
{
OnQuit(this, ref cancel);
}
}
and then do
word.Quit = WordOnQuit;
or
word.Quit += WordOnQuit;
But it's not possible to assign the delegate for WordOnQuit to the dynamic object word.Quit. So how to capture this event?
[1] http://msdn.microsoft.com/en-us/library/aa211898(v=office.11).aspx