i'm trying to coding vb.net and i'm in a hard situation beacuse i don't know why cant running my code Purpose is Checking CheckBox Control(Form Control in Excel) is Checked Or UnChecked
Here is Code and error is BC30512 String,Integer convert Error in IF condition
Dim Message As String
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlWb As Microsoft.Office.Interop.Excel.Workbook
xlWb = xlApp.Workbooks.Open(my_excel_path)
Dim xlSt = As Microsoft.Office.Interop.Excel.Worksheet = CType(xlWb.Worksheets(sheet_name),Worksheet)
**If (xlSt.Shapes("Check Box 1").OLEFormat.Object.Value = 1) Then**
Message = "is Checked"
Else
Message = "is UnChecked"
End If
MsgBox(Message)
plz help me
I need a correct grammar i tried xlSt to ActiveSheet.Shapes() and this isn't work (it worked in vba Excel, so i tried)
and my new Code is
Dim excelApp As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application
Dim xlWorkbook As Microsoft.Office.Interop.Excel.Workbook = Nothing
Dim xlWorksheet As Microsoft.Office.Interop.Excel.Worksheet = Nothing
Dim shape As Microsoft.Office.Interop.Excel.Shape = Nothing
xlWorkbook = excelApp.Workbooks.Open(FilePath)
'Get the worksheet
xlWorksheet = CType(xlWorkbook.Sheets("Sheet1"), Microsoft.Office.Interop.Excel.Worksheet)
Dim checkBoxNames() As String = {"Check Box 1", "Check Box 2", "Check Box 3", "Check Box 4","Check Box 5","Check Box 6","Check Box 7"} 'Add more names here as needed
Dim isChecked As Boolean
For Each checkBoxName In checkBoxNames
For Each shape In xlWorksheet.Shapes
If shape.Name = checkBoxName Then
isChecked = (CInt(shape.ControlFormat.Value) = 1)
Console.WriteLine(checkBoxName & ": " & isChecked.ToString())
Exit For
End If
Next
Next
xlWorkbook.Close()