View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Amit Kathuria Amit Kathuria is offline
external usenet poster
 
Posts: 1
Default Retrieving the values of Excel check boxes in .NET

I have an Excel spreadsheet which contains multiple un-grouped check boxes
(from the Forms toolbar) which are not linked to any particular cell(s). I
want to read their values in .NET code. For this I'm using 'Microsoft Office
Interop Excel' and 'Microsoft Vbe Interop Forms' libraries. This is the code
I'm using:

String excelFile = "C:\\FileName.xls";
Excel.Application estimate = new Excel.Application();
Excel.Worksheet workSheet = new Excel.Worksheet();
estimate.Workbooks.Open(excelFile, 0, true, 5, "", "", false,
Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
workSheet =
(Excel.Worksheet)estimate.Worksheets.get_Item("Wor ksheetName");
Excel.CheckBox cb =
(Excel.CheckBox)workSheet.Shapes.Item("CheckBoxNam e").OLEFormat.Object;

cb.Value returns the value of the check box (the value is -4146 if the check
box is unchecked, 1 if it is checked and null if it is mixed).

At some point in time I was able to see the names of all the check boxes in
my worksheet (they were named "Check Box 1", "Check Box 2" and so on). But
now I see that all the check boxes have the same name "CheckBox" which is
very strange. This is making it impossible for me to retrieve the values of
the check boxes by specifying the check box name. I know I can use the index
also but it poses a similar problem - 'how do I know the index of each check
box?'. Coming back to the name issue, is there any way I can see the unique
names of all my check boxes again? Is there any mode which I have to use to
be able to see the unique names? What am I missing here?

Any help would be greatly appreciated. Thanks in advance.