If you want to consume MS Word events within an existing VS.NET C# Project use Automation:
Add a reference to the Word interop assembly in your Project. If it is not available in the .NET tab of the Add Reference dialog,
then click "Browse..." and locate the MS Word executable and add a reference to it instead.
Research if there is a Word Primary Interop Assembly, which should be referenced if avialable instead of the above solution. I'm
not sure if it's available, or for what versions of Word, at this time.
VS.NET will wrap it as a .NET assembly unless you choose one from the .NET tab, or reference a PIA (Primary Interop Assembly)
provided by MS. Once referenced, you can code against MS Word as you would any other .NET assembly, subscribing to events, etc.
To get an instance Word (running or new):
Declare a method:
/// <summary>Retrieves a reference to a running COM object with the specified ProgID or creates a new one.</summary>
public static object GetRunningObject(string ProgID)
{
try
{
// First, check the running object table (ROT)
return Marshal.GetActiveObject(ProgID);
}
catch {}
object instance = null;
try
{
// Create a new instance
Type type = Type.GetTypeFromProgID(ProgID, false);
instance = Activator.CreateInstance(type);
}
catch {}
return instance;
}
Invoke the method:
Word._Application word = GetRunningObject("Word.Application") as Word._Application
Subscribe to an event:
word.Application.DocumentOpen+=
new Word.ApplicationEvents2_DocumentOpenEventHandler(Application_DocumentOpen);