jper_hm
asked on
Excel Automation:Manual Calculation problem
Hi Experts,
I want to do Manual Calculation in Excel Automation with VC++/MFC. To do the equivalence of Excel/VBA
Application.Calculation = xlCalculationManual
I thought I could use
excel::_Application oExcel;
oExcel.SetCalculation((lon g)-4135);
Compilation goes fine, but error in run time. What's wrong here?
Thanks.
I want to do Manual Calculation in Excel Automation with VC++/MFC. To do the equivalence of Excel/VBA
Application.Calculation = xlCalculationManual
I thought I could use
excel::_Application oExcel;
oExcel.SetCalculation((lon
Compilation goes fine, but error in run time. What's wrong here?
Thanks.
ASKER
Thanks. What is vInt()? Which header file should I include?
JPER
JPER
what error u r getting .. pass it as a int
MAHESH
MAHESH
try
oExcel.SetCalculation(COle Variant((l ong)-4135) );
MAHESH
oExcel.SetCalculation(COle
MAHESH
ASKER
I cannot compile with vInt() nor oExcel.SetCalculation(COle Variant((l ong)-4135) );
vInt is not declared. I thought I should include some header file.
oExcel.SetCalculation(COle Variant((l ong)-4135) ); is just not right. SetCalculation parameter is long and not VARIANT.
vInt is not declared. I thought I should include some header file.
oExcel.SetCalculation(COle
vInt was by mistake.....
but what error code you are getting ? -1 / -2 / -3 ?? an also whats ur runtime error ?
MAHESH
but what error code you are getting ? -1 / -2 / -3 ?? an also whats ur runtime error ?
MAHESH
also post some more code
ASKER
try
oExcel.SetCalculation(COle Variant((l ong)-4135) );
get this compilation error:
'SetCalculation' : cannot convert parameter 1 from 'class COleVariant' to 'long'
Since I cannot run it, I do have the return value of the function.
There is nothing unique about my original code:
excel::_Application oExcel;
excel::Workbooks books;
excel::_Workbook book;
excel::Worksheets sheets;
excel::_Worksheet sheet;
excel::Range range, range1, cols;
oExcel.SetDisplayAlerts(0) ;
oExcel.SetVisible(TRUE);
oExcel.SetUserControl(TRUE );
oExcel.SetScreenUpdating(F ALSE); //to speed up update macro code
oExcel.SetCalculation((lon g)-4135); //xlCalculationManual=-413 5
When it comes to the last line, an error ocurrs, saying "Runtime error! ...abnormal program termination"
oExcel.SetCalculation(COle
get this compilation error:
'SetCalculation' : cannot convert parameter 1 from 'class COleVariant' to 'long'
Since I cannot run it, I do have the return value of the function.
There is nothing unique about my original code:
excel::_Application oExcel;
excel::Workbooks books;
excel::_Workbook book;
excel::Worksheets sheets;
excel::_Worksheet sheet;
excel::Range range, range1, cols;
oExcel.SetDisplayAlerts(0)
oExcel.SetVisible(TRUE);
oExcel.SetUserControl(TRUE
oExcel.SetScreenUpdating(F
oExcel.SetCalculation((lon
When it comes to the last line, an error ocurrs, saying "Runtime error! ...abnormal program termination"
I am asking about your original error.... when u compile your code with just
excel::_Application oExcel;
oExcel.SetCalculation((lon g)-4135);
what is the code returned ? and also whats the run time error ?
MAHESH
excel::_Application oExcel;
oExcel.SetCalculation((lon
what is the code returned ? and also whats the run time error ?
MAHESH
ASKER
The error is "Runtime error! ...abnormal program termination".
If I step through the code, when it gets to oExcel.SetCalculation((lon g)-4135); I get "unhandled exception".
Since I get an error, I cannot get any returned code!
If I step through the code, when it gets to oExcel.SetCalculation((lon
Since I get an error, I cannot get any returned code!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have already made the workbook visible and controllable.
oExcel.SetVisible(TRUE);
oExcel.SetUserControl(TRUE );
oExcel.SetVisible(TRUE);
oExcel.SetUserControl(TRUE
i.e. 1st Activate Workbook and Worksheet and then Set calculation mode..
MAHESH
MAHESH
you need to open workbook and worksheet.. from your above code it seems you do not have any worksheet open in excel.. activate worksheet 1st and then set calculation mode
MAHESH
MAHESH
ASKER
Mahesh, you are right. If SetCalculation() is done after opening a worksheet, it works fine.
Thank you.
Thank you.
vInt(calcn, -4135);
oExcel.SetCalculation(calc
SetCalculation() sets "calculation mode" of excel's active workbook.ie automatic or manual
check return value of function....
values are as follows
1 is for success
-1 / -2 excel/workbook not active
-3 unknown error
what value you r geting ? also what runtime error message you are getting ?
MAHESH