09-05-2011 07:30 AM
Hi,
when i use Excel_NewApp, sometimes the function fails and i found that there is no EXCEL.exe created in Process Monitor at the same time.
Office 2007 is installed in this PC.
Does anyone knows the solution?
Regards.
09-05-2011 08:08 AM
Does the function return any error code?
Does this happen on the very first call or only on subsequent uses of these function? Are you sure you have closed any activeX handle previously opened?
Can you post the code you are using to call the function so that additional parameters are also known?
09-05-2011 07:39 PM
Hi Roberto,
Thank you very much.
Does the function return any error code?
------------ i am catching the error message using CA_GetAutomationErrorString, and this may take sometime. i will update once i catch it.
Does this happen on the very first call or only on subsequent uses of these function?
------------ only on subsequent uses of these function.
Are you sure you have closed any activeX handle previously opened?
----------- i found no EXCEL.exe created in Process Monitor. and my code didn't creat other activeX handle.
Can you post the code you are using to call the function so that additional parameters are also known?
----------- SetWaitCursor (1);
error = Excel_NewApp (NULL, 0, LOCALE_NEUTRAL, 0, &ExcelAppHandle);
CA_GetAutomationErrorString ( error, ErrorMessage, 510);
MessagePopup("",ErrorMessage);
SetWaitCursor (0);
PS: the file's property is xls, but my windows office application is 2007 edition.
09-05-2011 09:55 PM
Hi,
Does the function return any error code?
------------------------ return error message is “Not enough storage is available to process this command”
Regards.
09-05-2011 11:50 PM
I never got this error, but I have found some informations here and here that may give you some hints on how to address your situation.
Are you running your app across a network?
Additionally, as you do not receive this error on the first call, I would suggest you to carefully check that you are correctly disposing of every ActiveX resource you may have opened before terminating the program. By this I mean that every reference to a workbook, worksheet, range, variant and so on you may have used in processing Excel data must be disposed of with its proper Clear command. Failing to do so may lead to unpredictable behaviour in subsequent access to ActiveX resources.
10-17-2012 04:29 AM
Hi all,
sorry that i have to dig out this old thread again.
I have the same problem with the Excel_NewApp.
My code looks like this:
static CAObjHandle ExcelAppHandle = 0;
static CAObjHandle ExcelWorkbookHandle = 0;
static CAObjHandle ExcelWorksheetHandle= 0;
error = Excel_NewApp (NULL, 0, LOCALE_NEUTRAL, 0, &ExcelAppHandle);
if(error<0)
{
MessagePopup(APP_AUTOMATION_ERR,LAUNCHERR);
error = 0;
goto Error;
}
else
{
error = Excel_SetProperty (ExcelAppHandle, NULL, Excel_AppVisible, CAVT_BOOL,TRUE);
if (error<0)
goto Error;
error = ExcelRpt_WorkbookNew(ExcelAppHandle,&ExcelWorkbookHandle);
if (error < 0)
goto Error;
error = ExcelRpt_GetWorksheetFromIndex(ExcelWorkbookHandle,1,&ExcelWorksheetHandle);
if (error < 0)
goto Error;
excel_address = RangeString(0,0,9,9);
ExcelRpt_WriteDataFromTableControl(ExcelWorksheetHandle,excel_address,active_tab_panel,TAB_BIN_BIN_TABLE);
// finish writing, clear handle
CA_DiscardObjHandle(ExcelWorksheetHandle);
CA_DiscardObjHandle(ExcelWorkbookHandle);
CA_DiscardObjHandle(ExcelAppHandle);
}
}
Error:
if (error < 0)
MessagePopup("Excel","Error handling excel");
On the first call of this function, it works, the excel is opened, new sheet is created and data from table is written into excel sheet.
But on the later call, the function just stops at Excel_NewApp. no error or anything return.
10-17-2012 06:40 AM
On one hand, you may try adding a call to Excel_AppQuit () function just immediately before discarding ExcelAppHandle (the behaviour seems associate to Excel not being closed properly by your function, so that the new call to NewApp fails or hangs).
On the other hand, I would move all CA_DiscardObjHandle functions after Error label, so that every existing resource is discarded even in case of errors that prevent the callback to terminate regularly.
10-17-2012 05:03 PM
Hi Roberto,
is it possible, to discard the handle but leave the application open ?
I want to write data into excel sheet, then it is up to the user to save it or not.
10-17-2012 11:55 PM - edited 10-17-2012 11:57 PM
This document explains how to address your situation.
You may want to try connecting to an existing Excel instance, if any, and open a new instance if not. Save this condition so that you know whether to close Excel on exit or not. See code in this post.
Alternatively you can always open a new instance of the program and close it when you have finished working on it.