我用的是标准com口嵌入excel表格的方式。
CLSID clsid; if(FAILED(::CLSIDFromProgID(L"Excel.addin",&clsid))) //sheet
AfxThrowMemoryException(); 然后得到lpDispatch
并用m_workbook得到这个接口。
然后在调用saveas方法之前想设置一下displayalerts的属性。在这里设断点单步能过,可一取消断点连续运行就会出错,说不能设置类Application的setDisplayAlerts属性麻烦高人指点一下
_Application app;
app.AttachDispatch(m_workbook.GetApplication());
app.SetDisplayAlerts(false);

解决方案 »

  1.   

    The fact that the error doesn't occur when you step through the code with the debugger, suggests that this may be some kind of timing or focus issue. 
    set app.visible to true before set the DisplayAlerts property to see what happens
      

  2.   

    改成这样了:
    Sleep(5000);
    BOOL KK=app.GetDisplayAlerts();
    Sleep(5000);
    app.SetDisplayAlerts(false);
    Sleep(5000);
    还是不行。。
    单步走没问题的。
    app.setvisible会显示excel程序的界面,这个是不允许的。而且设了也还是一样。说
    不能设置类Application的setDisplayAlerts属性
      

  3.   

    msdn那个是用app的,我用的是嵌到container里面的那种