2016-01-20 73 views
0

当我按下F3时,我想要插入一个新列,但是如果我按F3当我编辑某些列时 - 我的Excel崩溃。我该如何解决这个问题?当编辑列时Excel崩溃

if (checkModifiers() && (checkKey(Keys.F3))) 
{ 
    try 
    { 
     Workbook wb = Globals.ThisAddIn.Application.ActiveWorkbook; 
     Worksheet ws = Globals.ThisAddIn.Application.ActiveSheet; 
     Microsoft.Office.Interop.Excel.Range rng = (Microsoft.Office.Interop.Excel.Range)Globals.ThisAddIn.Application.ActiveCell; 

     Range col = rng.EntireColumn; 
     col.Insert(XlInsertShiftDirection.xlShiftToRight, false); 
     col.Interior.Color = System.Drawing.Color.DarkOrange; 


    } 
    catch(Exception ex) 
    { 
     MessageBox.Show(ex.ToString()); 
    } 
} 

我已经试过

Globals.ThisAddIn.Application.EnableEvents = false; 

Globals.ThisAddIn.Application.Interactive = false; 

,但它并没有帮助,或者我用他们在错误的道路。

enter image description here

+0

你可以设置一个断点来确切地看哪一行会导致崩溃吗? –

+0

@MattBurland它在col.Insert(XlInsertShiftDirection.xlShiftToRight,false)崩溃; –

回答