嘿伙计们,我想在按下命令按钮时创建一定数量的组合框。我无法弄清楚如何做到这一点,所以我将非常感谢你的帮助。这是我创建的代码:
Private Sub CommandButton1_Click()
Dim AttPoints As Integer, Result As String
Range("E1:Z4").ClearContents
AttPoints = Range("B2").Value
If AttPoints = 0 Then
Result = "You have selected 0 AttPoints!"
ElseIf AttPoints < 0 Then
Result = "You have selected a negative amount of AttPoints!"
ElseIf AttPoints > 0 Then
Dim i As Integer
For i = 5 To (AttPoints + 4)
Cells(1, i).Value = "Attachment point:" & (i - 4)
Next i
End If
Range("A1") = Result
End Sub
在for循环中,我创建了一行单元格,其中放置了文本附加点。 在这些文本中,我想要相同数量的组合框,如图所示。
答案 0 :(得分:1)
在循环中添加以下代码
Private Sub CommandButton1_Click()
...
Shapes.AddOLEObject ClassType:="Forms.Combobox.1", _
Left:=Cells(2, i).Left, Top:=Cells(2, i).Top, _
Width:=Cells(2, i).Width, Height:=Cells(2, i).Height * 2
...
End Sub
这应该会产生你想要的结果。