I have populated a column of check boxes, and attempted to set the value of them to true like so:
worksheet.CheckBoxes("Check").Value = True
This is my code:
Public Sub AddCheckboxColumnToSpreadsheet(filePath As String)
' Create Excel application
Dim excelApp As New Excel.Application
excelApp.Visible = False
' Open the workbook
Dim workbook As Excel.Workbook = excelApp.Workbooks.Open("C:\Desktop\Test.xlsx")
Dim worksheet As Excel.Worksheet = workbook.Sheets(1)
' Find the last used column and row
Dim lastCol As Integer = worksheet.Cells(1, worksheet.Columns.Count).End(Excel.XlDirection.xlToLeft).Column
Dim lastRow As Integer = worksheet.Cells(worksheet.Rows.Count, 1).End(Excel.XlDirection.xlUp).Row
' Insert a header for the checkbox column
worksheet.Cells(1, lastCol + 1).Value = "Check"
' Loop through each row and add a checkbox
For row As Integer = 2 To lastRow
Dim leftPos As Double = worksheet.Cells(row, lastCol + 1).Left + 2
Dim topPos As Double = worksheet.Cells(row, lastCol + 1).Top + 2
Dim cbWidth As Double = worksheet.Cells(row, lastCol + 1).Width - 4
Dim cbHeight As Double = worksheet.Cells(row, lastCol + 1).Height - 4
worksheet.CheckBoxes.Add(leftPos, topPos, cbWidth, cbHeight).Select()
worksheet.CheckBoxes("Check").Value = True
excelApp.Selection.Caption = ""
Next
' Save and close
workbook.Save()
workbook.Close(False)
excelApp.Quit()
' Release COM objects
ReleaseComObject(worksheet)
ReleaseComObject(workbook)
ReleaseComObject(excelApp)
End Sub