From an application level add-in, can I make sure that this is attached to every document created / opened
From my add-in startup event I attach as follows:
private
void ThisAddIn_Startup(object sender, System.EventArgs e){
this.Application.DocumentOpen += new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentOpenEventHandler(Application_DocumentOpen);
}
Note the use of the ApplicationEvents4 (not supposed to be used by end user code! ). There is no event at this level for DocumentCreate.
And then in the event handler I CAST the document to the Tools namespace and attach the BeforeSave event....
// Attach beforesave to each document
void Application_DocumentOpen(Microsoft.Office.Interop.Word.Document doc){
((Microsoft.Office.Tools.Word.
Document)doc).BeforeSave += new SaveEventHandler(ThisAddIn_BeforeSave);}
Nasty code for something that should be quite simple Anyone know what I'm missing
Ken