0

I'm trying to get the value of a check box from an Excel sheet. I found something that appears to come close, but it falls short:

xl.OLEObjects oleObjects = AddressWorksheet.OLEObjects() as xl.OLEObjects;
foreach (xl.OLEObject item in oleObjects)
{
    //VBE.CheckBox xlCB = item.Object as VBE.CheckBox;
    var xlCB = item.Object as VBE.CheckBox;
    Console.WriteLine("checkbox: " + item.Name);
    Console.WriteLine("Value: " + xlCB.get_Value());
    Marshal.ReleaseComObject(xlCB); xlCB = null;
}

This gives me an error of "Unable to get the Object property of the OLEObject class"

Is there anything that actually works though? Seems like it's something you should be able to do.

  • Did you see [this question](https://stackoverflow.com/questions/39351011/reach-activex-or-form-objects-textbox-from-codebehind-in-an-excel-document)? In your code, the `if (item.progID == ...` part is missing. And please note that there are two types of checkboxes in Excel - perhaps you have a standard `Forms` checkbox instead of an ActiveX checkbox. – ventiseis Nov 17 '16 at 20:59
  • Ah yes, I think I have the forms checkbox. The progID throws an error, but there's only one thing on that form anyway. That error is: {"Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"} – Justin Kofford Nov 18 '16 at 16:32

0 Answers0