LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

More help on LabWindows/CVI ActiveX Automation

How to get more help detail of ActiveX automation libraries with CVI examples instead of a list of them? How to get the method or property ID? Right now, I want to modify the Excel2000 demo code to select the 2nd worksheet instead of the 1st worksheet. The help file is about VBA. I used Excel_SheetsSelect. It doesn't look right. It will be great if someone can tell me that and I will appreciate that
0 Kudos
Message 1 of 9
(4,366 Views)
In the example (excel2000dem.prj), the program gets a handle to the first worksheet on line 322 with the code:

error = Excel_SheetsItem (ExcelSheetsHandle, NULL, CA_VariantInt(1), &ExcelWorksheetHandle);

If you refer to the help for this function, you will see it returns a specific worksheet from a collection of worksheets. In this case, it is returned the first worksheet as specified by the 3rd argument CA_VariantInt(1). If you want the second worksheet, you would change the 1 to 2, which would be:


error = Excel_SheetsItem (ExcelSheetsHandle, NULL, CA_VariantInt(2), &ExcelWorksheetHandle);

ActiveX programming takes some time to get used to. When looking at the example, pay close attention to the sequence of ActiveX calls that are taking p
lace and try to understand what each function in the sequence is doing.


Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 9
(4,366 Views)
Chris, thank you for your quick response. However, after I did what you said, I got the error message "Exception Occured" while I clicked the button "Write Data" on the GUI. And I found in the Excel2000.c, on line 5476 Excel_SheetsItem() calls CA_InvokeHelper(... index) in which the index is the CA_VariantInt(1) in Excel_SheetsItem() and is the DISPATCH_PROPERTYGET. I guess CA_VariantInt(1) means this constant. But I still don't know how to select WorkSheet 2 in the Excel2000.

It will be greatly appreciate if you have more information about this. I am using LabWindows/CVI 5.5.


Thanks.
0 Kudos
Message 3 of 9
(4,366 Views)
I wasn't saying you could change that one line in the example and the example would work. I was saying that the sequence function you need to select a worksheet is the Excel_SheetsItem() function and I was pointing you to the example to see how it was used.

That being said, I changed the code as I said previously (on line 395 change CA_Variant(1) to CA_Variant(2)) and the Write Data button worked perfectly.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 4 of 9
(4,366 Views)
Yes, I changed CA_Variant(1) to CA_Variant(2) on line 395 in the function Excel_Sheetsitem() in the callback OpenAppFile(). After I hit Write Data Button, I got "Exception occurred".

BTW, which operating system are you using?

Thanks.
0 Kudos
Message 5 of 9
(4,366 Views)
I'm using WinXP and Office XP. The OS shouldn't really matter. The version of Office could make a difference, but I doubt it as long as you are using Office 2000 or greater. I'm not sure why you are getting the exception since I can't reproduce it.

Chris
0 Kudos
Message 6 of 9
(4,366 Views)
Hi, Chris,

I use Labwindows/CVI 5.5 and Office 2000 on Windows 95. I also try Office 2000 and CVI5.5 on Win XP and get the same error message. Which version of LabWindows/CVI are you using? I think CVI 6.0 is for Win 95/98/NT/2000 from the information published on NI LabWindows/CVI FAQ.

I will appreciate it if you can reproduce it.


Thank you for your time and effort you have spent and will spend.
0 Kudos
Message 7 of 9
(4,366 Views)
Ah, I didn't know you were using CVI 5.5. I went back to 5.5 and there was a small error in the example that is causing the problem. On the line after the function call to the Excel_SheetsItem function call, there is a function call to Excel_SetProperty that sets the worksheet to Visible. This is supposed to be a function call to make the worksheet the "Active" worksheet, not visible. If a worksheet isn't active you can't read or write to it.

Replace the line:
error = Excel_SetProperty (ExcelWorksheetHandle, NULL, Excel_WorksheetVisible, CAVT_LONG, ExcelConst_xlSheetVisible);

with:

error = Excel_WorksheetActivate(ExcelWorksheetHandle, NULL);

and that should fix your problem.
0 Kudos
Message 8 of 9
(4,366 Views)
I got it now, thank you, Chris, NI online help.
0 Kudos
Message 9 of 9
(4,366 Views)