Home > Net >  C # call excle macros for regression analysis
C # call excle macros for regression analysis

Time:10-04

Recently the company have a project, to call after the database data into EXCEL macro to regression analysis of data, now had a death data of macro file, but call macros when don't work has been submitted to the macro,,, specific error please see pictures, the following code
 ApplicationClass app=null; 
Workbook Workbook=null;
VBComponent VBComponent=null;

String strCode;
The Object oMissing=System. Reflection. Missing. The Value;
The Object missing=System. Reflection. Missing. The Value;
App=new ApplicationClass ();


WorkBook=app. Workbooks. Open (@ "D: \ ExcelHong \ test0917-1. XLSM", missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
VbComponent=workBook. VBProject. VBComponents. Add (vbext_ComponentType. Vbext_ct_StdModule);
# region
StrCode="Sub hong201909 () \ r \ n" +
"The Range (" A2 \ "). Select \ r \ n "+
"ActiveCell. FormulaR1C1=" and \ "\ r \ n +"
"The Range (" B2 \ "). Select \ r \ n "+
"ActiveCell. FormulaR1C1=" 44 \ \ r \ n "+"
"The Range (" B3 \ "). Select \ r \ n "+
"ActiveCell. FormulaR1C1=" 55 \ \ r \ n "+"
"The Range (" A3 \ "). Select \ r \ n "+
"ActiveCell. FormulaR1C1=" 555 \ "\ r \ n" +
"The Range (" A4 \ "). Select \ r \ n "+
"ActiveCell. FormulaR1C1=" 7665 \ "\ r \ n" +
"The Range (" B4 \ "). Select \ r \ n "+
33 "ActiveCell. FormulaR1C1=" \ "\ r \ n +"
"The Range (" A5 \ "). Select \ r \ n "+
"ActiveCell. FormulaR1C1=" and \ "\ r \ n +"
"The Range (" B5 \ "). Select \ r \ n "+
"ActiveCell. FormulaR1C1=" 55 \ \ r \ n "+"
"The Range (" A6 \ "). Select \ r \ n "+
"ActiveCell. FormulaR1C1=" and \ "\ r \ n +"
"The Range (" B6 \ "). Select \ r \ n "+
"ActiveCell. FormulaR1C1=" 66 \ "\ r \ n" +
E8 "Range (" \ "). Select \ r \ n "+
"Application. The Run " ATPVBAEN XLAM! Regress \ ", ActiveSheet. Range (\ "$A $2: $A $6 "), _ \ r \ n "+
"ActiveSheet. Range (" $B $2: $B $6 \ "), True, False, and ActiveSheet. Range (\ "$$8 A "), _ \ r \ n "+
"True, True, True, True, True \ r \ n" +
"End Sub";

# endregion

VbComponent. CodeModule. Method AddFromString (strCode);
Try
{
App. Run (" hong201909 ", missing, missing,
Missing, missing, missing, missing, missing, missing, missing,
Missing, missing, missing, missing, missing, missing, missing,
Missing, missing, missing, missing, missing, missing, missing,
Missing, missing, missing, missing, missing, missing, missing);
}
The catch (Exception ex)
{

GC. Collect ();
}
App. The Visible=true;
App. UserControl=true;
VbComponent=null;
WorkBook=null;
App=null;
GC. Collect ();


Looked for a few days haven't sort out a clue to see what a great god can help
  •  Tags:  
  • C #
  • Related