나는 Excel COM 추가 기능을 만듭니다. 이제 WorkbookBeforeClose 이벤트를 제어하려고합니다.
그러나 내가 찾은 솔루션 Stackoverflow (c# using the event handler WorkbookOpen) 나를 위해 작동하지 않습니다.
내 추가 기능에는 InternalStartup Sektion이 없으며 Load Sektion 만 있습니다.
리본 바에있는 버튼을 눌러서 만 이벤트 핸들러를 시작할 수 있습니다.
내가 버튼 1x를 누르면 Eventhandler는 Excel이로드되는 모든 시간을 원하는대로 처리합니다.
Excel을 닫은 후 다시 시작하면 버튼을 다시 눌러야합니다.
Eventhandler ist가있는 방법 Excel이 첫 번째 빈 통합 문서를로드하는 동안 시작 하시겠습니까 ???
나를위한 도움이나 해결책이 있습니까 ???엑셀 addin 통합 문서 닫기 이벤트
감사합니다 감사합니다
스테판 여기
내 코드는 내가 이벤트 핸들러에 사용하는,이다
public partial class Excel2SE
{
Excel.AppEvents_WorkbookBeforeCloseEventHandler EventDel_BeforeBookClose;
private void Excel2SE_Load(object sender, RibbonUIEventArgs e)
{
EventDel_BeforeBookClose = new Excel.AppEvents_WorkbookBeforeCloseEventHandler(BeforeBookClose);
}
private void btn_Start_Click(object sender, RibbonControlEventArgs e)
{
wbEventhandlerStart();
}
private void wbEventhandlerStart()
{
Excel.Application app = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
app.WorkbookBeforeClose += EventDel_BeforeBookClose;
}
// This Works when Excel Close
private void Excel2SE_Close(object sender, EventArgs e)
{
MessageBox.Show("Excel close");
}
// This works after Pushing the Start Button and the Workbook Close
private void BeforeBookClose(Excel.Workbook Wb, ref bool Cancel)
{
MessageBox.Show("WB close");
}