Hi Xinwen
Let me make sure I understand correctly. This is a VSTO solution, and you want to capture when the user creates a new workbook
The NewWorkbook event is an application level event. Since there's also a property of the same name, Intellisense won't show this to you unless you explicitly cast the application object to the application events:
((Excel.AppEvents_Event)ThisApplication).NewWorkbook += new Microsoft.Office.Interop.Excel.AppEvents_NewWorkbookEventHandler(ThisWorkbook_NewWorkbook);
The event handler:
void ThisWorkbook_NewWorkbook(Microsoft.Office.Interop.Excel.Workbook Wb) { MessageBox.Show("New workbook" + Wb.Name); }
The procedure you were trying to work with is only valid in the ThisWorkbook VBA project. It can't be used outside the immediate Excel environment.
|