LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how i can get and select an Excel Worksheet by its name??

How can i get an specific worksheet, by its name.
I do the following based in another example about the workbooks:

// Get the active Worksheets
Excel_GetProperty(ExcelSheetsHandle,NULL,Excel_WorksheetsCount, CAVT_LONG,&ExcelSheetsNumber);

for (i=1;i<=ExcelSheetsNumber;i++)
{
Excel_WorksheetsItem (ExcelSheetsHandle, NULL, CA_VariantInt(i), &hCurrentSheet);
Excel_GetProperty (hCurrentSheet, NULL, Excel_WorksheetName,CAVT_CSTRING, WorksheetName); SetStdioWindowVisibility (1);
printf(" %s",WorksheetName);
}
......

I put an Stdio Window to see the effect of the variable that i get, but its split only garbage

How can I get the string of the Worksheet and select this wor
ksheet by its name???

I would apreciate your help !!

Eduardo Zagal
0 Kudos
Message 1 of 3
(3,016 Views)
Hello


The way the excel object model is setup, you have first get a handle to the application object.

error = Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppSheets,
CAVT_OBJHANDLE, &ExcelSheetsHandle);


Then use the following function to get a handle to the worksheet object based on the name

CA_VariantSetCString (&sheetVariant, "Sheet2");

error = Excel_SheetsItem (ExcelSheetsHandle, NULL, sheetVariant,
&ExcelWorksheetHandle);


once you have this, you can make it active.

error = Excel_WorksheetActivate (ExcelWorksheetHandle, NULL);


Refer to the CVI Excel shipping example for more info on this, found at ..\CVI\samples\activex\excel\.
Also check out the excel activex object m
odel on how this is setup in excel. You'll be able to get information on this from the MSDN.

Hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
Message 2 of 3
(3,016 Views)
Thanks for your help !!
It's exactly that i was looking for !!!

Regards

Eduardo
Message 3 of 3
(3,016 Views)