LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Excel_NewApp fails sometimes

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.

 

0 Kudos
Message 1 of 9
(4,070 Views)

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?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 9
(4,068 Views)

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. 

0 Kudos
Message 3 of 9
(4,063 Views)

Hi,

    Does the function return any error code?

     ------------------------ return error message is “Not enough storage is available to process this command”

Regards.

0 Kudos
Message 4 of 9
(4,059 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 5 of 9
(4,055 Views)

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.

 

0 Kudos
Message 6 of 9
(3,981 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 9
(3,974 Views)

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.

0 Kudos
Message 8 of 9
(3,865 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 9
(3,858 Views)