如何在Excel电子表格中为每行添加表单控件到单元格

时间:2022-01-08 07:16:17

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.

我如何在Excel中添加表单控件到单元格,我知道我可以绘制它,但我需要使它成为每一行的成员,并且它的值附加到该单元格/行。

1 个解决方案

#1


0  

There are several ways to do this but the easiest, assuming Excel 2007 is:

有几种方法可以做到这一点,但最简单的,假设Excel 2007是:

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:

你必须对放置进行一些实验,因为我认为没有直接的方法将控件与特定单元格对齐。另一种方法是使用工作表的Shapes集合:

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.

但是,请记住,上面的方法返回一个Shape对象而不是CheckBox对象,因此您无法直接操作其属性。有类似的方法,如使用OLEObjects集合,但这只是增加了更多的痛苦。

#1


0  

There are several ways to do this but the easiest, assuming Excel 2007 is:

有几种方法可以做到这一点,但最简单的,假设Excel 2007是:

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:

你必须对放置进行一些实验,因为我认为没有直接的方法将控件与特定单元格对齐。另一种方法是使用工作表的Shapes集合:

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.

但是,请记住,上面的方法返回一个Shape对象而不是CheckBox对象,因此您无法直接操作其属性。有类似的方法,如使用OLEObjects集合,但这只是增加了更多的痛苦。