问题
Here is the error:
Error 2 Cannot assign to 'Activate' because it is a 'method group'
Warning 1 Ambiguity between method 'Microsoft.Office.Interop.Excel._Workbook.Activate()' and non-method 'Microsoft.Office.Interop.Excel.WorkbookEvents_Event.Activate'. Using method group.
I can use
myWorkbook.Deactivate += new Excel.WorkbookEvents_DeactivateEventHandler(ThisWorkbook_Deactivate);
because there is no deactivate() method for a workbook. There is a Activate() method, which i DO NOT want to use. I'm wanting to handle the workbook Activate event like this, but i get the error above
myWorkbook.Activate += new Excel.WorkbookEvents_ActivateEventHandler(ThisWorkbook_Activate);
Any thoughts?
回答1:
See here http://bishoponvsto.wordpress.com/category/vsto/vsto-issues/
"Activate is both a method and an event of Application.Excel, so the Activate keyword must be cast to either an event or method."
来源:https://stackoverflow.com/questions/9610285/excel-workbook-activate-event-ambiguity-for-c-sharp-vsto