PDA

View Full Version : checkbox in excel



Theertha
01-03-2018, 03:53 PM
Hi
How do I check a checkbox in excel programmatically.
I have an excel which contains checkboxes inside group (Group1 contains CheckBox1 and CheckBox2 )
I want to check CheckBox1 with my VB program.

Dim xls = New Microsoft.Office.Interop.Excel.Application
Dim xlsWorkBook = xls.Workbooks.Open("C:\Users\theertha.padman\Desktop\check.xlsx")
Dim xlsWorkSheet = xlsWorkBook.Sheets("sheet1")
xls.Visible = True

Dim cb As Microsoft.Office.Interop.Excel.CheckBox
cb = CType(xlsWorkSheet.Checkboxes("CheckBox1"), Microsoft.Office.Interop.Excel.CheckBox)
cb.Value = True
i am getting a runtime error System.Runtime.InteropServices.COMException occurred
HResult=0x800A03EC
Message=Unable to get the CheckBoxes property of the Worksheet class