简体   繁体   中英

How do you add a forms controls to a cell in a Excel spreadsheet for each row

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM