WordDoc.CheckBoxNum.Value = CheckBoxVal
To be clear, I am working with an ActiveX control \"Checkbox\".
Unfortunately we cannot refer to an ActiveX control directly by its name using WordDoc.InlineShapes(CheckBoxNum)
, this only works if we know its index number: WordDoc.InlineShapes(1)
.
This means that you have to loop through all the controls, comparing its OLEFormat.Object.Name
to the name you are looking for:
Dim obj As Object
For i = 0 To 6 ' number of rows in table
'get from excel
CheckBoxNum = ActiveCell.Offset(i, k + 1).Value
CheckBoxVal = ActiveCell.Offset(i, k).Value
For Each obj In WordDoc.InlineShapes
If obj.OLEFormat.Object.Name = CheckBoxNum Then
obj.OLEFormat.Object.Value = CheckBoxVal
End If
Next obj
Next i
AFAIK, you can use:
WordDoc.InlineShapes(CheckBoxNum).OLEFormat.Object.Value = CheckBoxVal