LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

excel2000dem exception when selecting sheet 2

I am about to start a development in which I have to get data interactively from an excel workbook.

I checked excel200dem example project (located in National Instruments\CVI80\samples\activex\excel ), which ran fine until I selected the second sheet (sheet2).
I get an exception when executing the line  error = Excel_RangeActivate (ExcelRangeHandle, &ErrorInfo, NULL);

Can someone explain me why I get an exception ? and give a clue on how to fix this issue, because I will have to handle several sheets.

Thanks.

Jolaf.
0 Kudos
Message 1 of 7
(4,141 Views)
Hi,

I ran the same exemple, I can't manage to get an exception. Even when I use several sheets...
What do you do exactly ? Just open the project and run ?
Let me know

Regards,

Richard Keromen

0 Kudos
Message 2 of 7
(4,126 Views)
I start the program in either debug or release mode.

I click ( with either an already started excel, or no excel started) on launch excel (or connect to excel) then open file, then I select sheet2, then click on write data -> nothing written & message saying that an exception has occured.

My excel is excel 2000 with some patches, CVI 8.0.0

Jolaf'
0 Kudos
Message 3 of 7
(4,107 Views)
Normally CVI handles multi-sheet files without problems, so if you get an exception you should verify that all parameters passed to the function are valid handles or objects.
 
First of all, does the second sheet actually exists? Depending on Excel options, a newly created file may have only one sheet, so if this is your case you may be getting errors. To determine if a second sheet does exist and select/create it you can use these lines:
 
 errChk (Excel_GetProperty (ExcelSheetsHandle, NULL, Excel_SheetsCount, CAVT_LONG, &cnt));
 if (cnt < 2)
  // Create a new sheet if necessary
  errChk (Excel_SheetsAdd (ExcelSheetsHandle, NULL, CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL, &ExcelWorksheetHandle));
 else
  // Select sheet 2
  errChk (Excel_SheetsItem (ExcelSheetsHandle, NULL, CA_VariantInt(2), &ExcelWorksheetHandle));
 // Activate sheet
 errChk (Excel_WorksheetActivate (ExcelWorksheetHandle, NULL));
 
After this and if the range handle is valid, check error code after every function in your code: you may be getting in RangeActivate an error inherited from a previous call not monitored.
 
Finally, are you passing an ErrorInfo structure to the function? And does it add any useful detail to the error message?


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 4 of 7
(4,084 Views)
Great, it works !
But I can't understant what is wrong. There seems to be a difference between a "selected" and an "activated" sheet.

How can I adapt this in order to work with the sheet selected by the user ?

I guess that there must be a function that allows to get the number of the sheet actually selected (I can't find it)
What happends if there are two sheets selected ?

Regards,

Jolaf'
0 Kudos
Message 5 of 7
(4,057 Views)
It's my opinion that "selected" term inside Excel instrument has no relation to selection of sheets the user interactively operates. Within the Excel instrument, "selection" means only the choice of the object on which to operate in some way, while activating means making the selected object the active one for reading / writing and so on.


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 6 of 7
(4,048 Views)
So I have to activate the worksheet selected by the user.

But I can't find how to get this information.

Can you help one more time ?

Jolaf'

0 Kudos
Message 7 of 7
(4,021 Views)