How do i add a forms control in excel to a cell, I know I can draw it, but I need to make it a member 开发者_运维问答of each row and it's values attached to that cell/row.
There are several ways to do this but the easiest, assuming Excel 2007 is:
Set cb = MyWorkSheet.CheckBoxes.Add(left, top, width, height)
cb.LinkedCell = "$A$1"
cb.Display3DShading = True
You have to experiment a little with placement as I don't think there is a direct way to align the control with a particular cell. Another way would be to use the Shapes
collection of the worksheet:
Set shape = MyWorkSheet.Shapes.AddFormControl(xlCheckBox, l, t, w, h)
However, keep in mind that the above method returns a Shape
object and not a CheckBox
object so you can't manipulate its properties directly. There are similar methods to the above like using the OLEObjects
collection but that's just adding more pain.
精彩评论