[英]VBA: Cannot add item to combobox
I am trying to add some items via VBA into a dropdown list. 我正在尝试通过VBA将一些项目添加到下拉列表中。 Whenever I set the combo variable I get a 13 error.
每当我设置组合变量时,都会出现13错误。 I don't get to set the combo variable as a combobox from the libro sheet, therefore I cannot use the combobox.additem property, how can I set that straight?
我没有从libro表中将combo变量设置为combobox,因此无法使用combobox.additem属性,如何设置该值呢?
Sub Prueba()
Dim libro As Worksheet
Dim combo As ComboBox
Set libro = ActiveWorkbook.Sheets("Tabla Paquetes")
Set combo = libro.Shapes("ComboBox1")
With combo
.AddItem "Paris"
.AddItem "New York"
.AddItem "London"
End With
End Sub
Your combo box is NOT a shape, so your code won't find it in the Shapes
collection. 您的组合框不是形状,因此您的代码在
Shapes
集合中找不到。
Instead, do the following: 而是,请执行以下操作:
Sub Prueba()
Dim libro As Worksheet
Dim combo As ComboBox
Set libro = ActiveWorkbook.Sheets("Tabla Paquetes")
'Set combo = libro.Shapes("ComboBox1")
With ComboBox1 ' assuming the name of your control is "ComboBox1"
.AddItem "Paris"
.AddItem "New York"
.AddItem "London"
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.