2013-11-04 4 views
1

나는 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"); 
} 

답변

1

이 비주얼 스튜디오 오피스 추가 기능인가?

private void ThisAddIn_Startup(object sender, EventArgs e) 
{ 

} 
private void ThisAddIn_Shutdown(object sender, EventArgs e) 
{ 

} 

당신은 당신이 ThisAddIn_Shutdown 방법 가까이에서 실행하고자하는 코드를 추가 할 수 있습니다 : 그것은이 같은 다음과 같은 2 가지 방법에 대한 ThisAddIn.cs을 확인할 경우, 소리. 이 코드를 실행할 수있는 방법은 없지만 사용자가 Excel을 제대로 닫으면 실행됩니다. 작업 관리자 등을 사용하여 작업을 종료하면 모든 배팅이 해제됩니다.

관련 문제