LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to view an existing .xls file with excel2000.fp?

I am using CVI 5.5 under win2k. I can launch a copy of Excel 2000 with

Excel_NewApp (NULL, 1, LOCALE_NEUTRAL, 0, &CAOApp);

It works fine.
I can also make it visible. But I can't seem to open an existing .xls file within it. I have tried Excel_WorkbooksOpen(), but I get a return code of DISP_E_MEMBERNOTFOUND. I have tried almost every call in the .fp, and can't get it to work. Please advise.
0 Kudos
Message 1 of 6
(3,696 Views)
The Excel_WorkbooksOpen() method is a method on the Workbooks object NOT the application object. You have to get the Workbooks collection property from the application object first, then call the function with that handle. I.E.

Excel_NewApp (NULL, 1, LOCALE_NEUTRAL, 0, &CAOApp);
Excel_GetProperty (CAOApp, NULL, Excel_AppWorkbooks,
CAVT_OBJHANDLE, &hWorbooks);
Excel_WorkbooksOpen (hWorkbooks, NULL,
"c:\\\\/.xls",
CA_DEFAULT_VAL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_DEFAULT_VAL,

CA_DEFAULT_VAL, CA_DEFAULT_VAL,
&hWorkbook);

By the way, you are most likely going to have a constant stream of questions like this in programming Excel. I would recommend you upgrade to CVI 6.0. We have a new tool call the Excel Report instrument driver that allows you to easily do most common functions in Excel without knowing the low-level ActiveX API programming.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 6
(3,696 Views)
Yes CVI 6.0. I was in the beta for that. I expected to get a gratis upgrade. Is this still the policy?
-Rich
0 Kudos
Message 3 of 6
(3,696 Views)
No, actually we have never done that. We do really appreciate your participation in the beta program.

Chris
0 Kudos
Message 4 of 6
(3,696 Views)
Chris, I respectfully disagree on that issue. I have been in beta's in the past with CVI that offered more than just a polite thank you. Anyway, I have one more issue. Everything works fine now, except when I end Excel and run the code at the bottom of this message. When I go into the task manager, Excel is still running. I am running this code to stop it and all the return codes are AOK.

iRc = Excel_SetProperty (CAOApp, NULL, cel_AppVisible, CAVT_BOOL, VFALSE);

iRc = Excel_WorkbookClose (CAOWorkbook, NULL, CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL);

iRc = Excel_WorkbooksClose (CAOWorkbooks, NULL);

iRc=Excel_AppQuit (CAOApp, NULL);
0 Kudos
Message 5 of 6
(3,696 Views)
I ran the last three beta programs and we didn't give anything away to beta users, but I'm sorry if you had that expectation. We can try to make it clearer in the beta program documentation. As for your question, you have to discard the all of the ActiveX handles that you opened with CA_DiscardObjHandle. In your case that would be the handle to the application, the workbooks collection, and the workbook you opened.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 6 of 6
(3,696 Views)