以编程方式在单元格内插入ComboBox
我想在活动单元格内插入对象curCombo
combobox,而没有定义宽度和高度。 在我的一些testing中,我工作了这样一个原则,但是我没有得到那样的工作
Set curCombo = ActiveSheet.Shapes.AddFormControl(.Left, .Top, .Width, .Height)
这是我的代码:
Sub comboBox1() Dim curCombo As Object '// Main challange is this set procedure here. Set curCombo = ActiveSheet.Shapes.AddFormControl(xlDropDown, _ Left:=Cells(ActiveCell.Row, 3).Left, _ Top:=Cells(ActiveCell.Row, 3).Top, Width:=100, Height:=20) With curCombo .ControlFormat.DropDownLines = 3 .ControlFormat.AddItem "1", 1 .ControlFormat.AddItem "2", 2 .ControlFormat.AddItem "3", 3 .Name = "myCombo" & ER.Row '.OnAction = "myCombo_Change" & ER.row End With End Sub
你的意思是你指定的是哪个细胞,它应该重叠吗? – Siddharth Rout 1小时前
是的先生。 Thant就是这样。 – AratioD 3分钟前
这是你正在尝试?
Sub comboBox1() Dim curCombo As Object Dim ws As Worksheet Dim rng As Range '~~> Change this to the relevant sheet Set ws = ActiveSheet With ws '~~> Change this to the relevant cell where '~~> you want the combobox Set rng = .Range("B5") Set curCombo = .Shapes.AddFormControl(xlDropDown, _ Left:=rng.Left, _ Top:=rng.Top, _ Width:=rng.Width, _ Height:=rng.Height) With curCombo .ControlFormat.DropDownLines = 3 .ControlFormat.AddItem "1", 1 .ControlFormat.AddItem "2", 2 .ControlFormat.AddItem "3", 3 .Name = "myCombo" & ER.Row '.OnAction = "myCombo_Change" & ER.row End With End With End Sub
截图