我正在使用VS2008 Addin,我正在尝试为插件中的工作簿编写和事件处理程序,但不幸的是它没有被解雇你可以帮助
公共部分类ThisAddIn {
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
FinalWorkbook = ExcelApplication.Workbooks.Add(missing);
FinalWorkbook.SheetActivate +=
new Excel.WorkbookEvents_SheetActivateEventHandler(
FinalWorkbook_ActivateSheet);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// MessageBox.Show("The addin has shutdown");
}
public void FinalWorkbook_ActivateSheet(object odjSheet)
{
sheet.BeforeRightClick += Worksheet_BeforeRightClick;
MessageBox.Show(sheet.Name + " Activated2");
}
void Worksheet_BeforeRightClick(Excel.Range Target, ref bool Cancel)
{
Cancel = true;
MessageBox.Show("Right-clicking in this sheet" +
" is not allowed.");
}
}
}
答案 0 :(得分:0)
SheetActivate仅在工作簿中的工作表之间切换时触发,即单击Sheet2,然后单击Sheet1,依此类推。 如果Alt-Tab到另一个应用程序并返回到Excel,则不会触发SheetActivate。
您应该查看Application.WorkbookActivate,Workbook.Activate或其他事件。