Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created one shared add-in in visual studio 2005. In this i fired three event for ms word
1)NewDocument(is fired when we open new word document)
2)DocumentOpen(is fired when already created word document is opened)
3)DocumentBeforeClose(is fired when document is closed (any new or already created))
but in my case NewDocument event is not working i don't knw why the last two event is working fine and the DocumentBeforeClose event is worked for new document also.
my code for new document is:-

public void OnStartupComplete(ref System.Array custom)
{
wb = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
if (wb.Documents.Count > 0)
{
object docIndex = 1;

MessageBox.Show(wb.Documents.Count.ToString() + "\r" + wb.Documents.get_Item(ref docIndex).Name);
}
((Word.ApplicationEvents4_Event)wb).NewDocument += new Word.ApplicationEvents4_NewDocumentEventHandler(Application_NewDocument);
}

void Application_NewDocument(Word.Document Doc)
{
MessageBox.Show("New: " + wb.ActiveDocument.Name);
openingTime = DateTime.Now.ToLocalTime();
}


why this event is not fired when i open new word document or can say on open MSword.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900