Discussion:
Accessing a Checkbox in EXCEL with a OleFunction
(too old to reply)
Werner Schmidt
2008-07-28 09:00:35 UTC
Permalink
Hi all.



I'm using Borland C++ 6 and want to read the property of a Checkbox and an
OptionButton placed in a excel worksheet.

I use the Olefunctions to access excel and try to access the Checkbox with
vMSExcel.OleFunction("getByName","CheckBox1");
but the olefunction getByName is unknown.

Does anyone knows, how to access a Checkbox or OptionButton ?

Thanks



Here is the Code:

vMSExcel = Variant::CreateObject ( "Excel.Application" );
vMSExcel.OlePropertySet ( "Visible", (OleVariant) true );
vXLWorkbooks = vMSExcel.OlePropertyGet ( "Workbooks" );

vFileName = sFile.c_str (); // c:\myfolder\myfile.xls
vXLWorkbook = vXLWorkbooks.OleFunction ( "Open", (OleVariant)
vFileName );

vSheetName = "Tabelle1";
vWorksheet = vXLWorkbook.OlePropertyGet ( "Worksheets",
vSheetName );

vCheckbox = vMSExcel.OleFunction("getByName","CheckBox1"); // this
is not working!!
bool bChechbox;
bCheckbox = vCheckbox.OlePropertyGet("State",0);
Minas
2008-07-28 22:18:27 UTC
Permalink
Post by Werner Schmidt
vSheetName = "Tabelle1";
vWorksheet = vXLWorkbook.OlePropertyGet ( "Worksheets",
vSheetName );
You have to use the OLEObjects collection to get the ole control
(OptionButton, CheckBox etc) you are looking for
Declare somewhere

PropertyGet Item("Item");

//....................

Variant oleObjs = vWorksheet .OlePropertyGet("OLEObjects");
int count = oleObjs.OlePropertyGet("Count");
for (int i=1; i <= count;i++)
{
Item.ClearArgs();
Variant obj = oleObjs.Exec(Item << i); // get the Object
Variant ctrl = obj.OlePropertyGet("Object"); // get the control
associated with the object obj
String ctrlName = ctrl.OlePropertyGet("Name"); // or String ctrlCap
=ctrl.OlePropertyGet("Caption")
if (ctrlName == "OptionButton1")
{
bool checked = ctrl.OlePropertyGet("Value");
if (checked)
//.... do something
else
//.... do something else
}
}
Post by Werner Schmidt
vCheckbox = vMSExcel.OleFunction("getByName","CheckBox1"); //
this is not working!!
bCheckbox = vCheckbox.OlePropertyGet("State",0);
GetByName and State do not exist

Best Regards
Minas Harokopos

Loading...