vba 列表框 ListFillRange
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22760758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Listbox ListFillRange
提问by Josh
I have inserted a form control listbox on my sheet. For some reason this errors out.
我在我的工作表上插入了一个表单控件列表框。出于某种原因,这会出错。
Sheet1.Shapes("ListBox1").ListFillRange = "A1:A10"
I'd like to fill the listbox with the range but I get a Run-time error '438', Object doesn't support this property or method. What am I missing here?
我想用范围填充列表框,但出现运行时错误“438”,对象不支持此属性或方法。我在这里缺少什么?
回答by Dmitry Pavliv
If it is Formlistbox, use this one:
如果是表单列表框,使用这个:
Worksheets("Sheet1").Shapes("ListBox1").ControlFormat.ListFillRange = "A1:A10"
or with Range
object:
或与Range
对象:
With Worksheets("Sheet1")
.Shapes("ListBox1").ControlFormat.List = .Range("A1:A10").Value
End With
回答by Starscream1984
You'll want to use something more like:
你会想要使用更像的东西:
Sheet1.ListBox1.ListFillRange = "A1:A10"
You were trying to find a Shape
object called "ListBox1" and then run a method that Shape
objects don't have.
您试图找到一个Shape
名为“ListBox1”的对象,然后运行一个Shape
对象没有的方法。
Edit v2: I see, in that case a cast would be needed (and they work differently from vb.NET), I think this could work:
编辑 v2:我明白了,在这种情况下,需要一个演员表(它们的工作方式与 vb.NET 不同),我认为这可以工作:
Dim myListBox as ListBox
SET myListBox = Sheet1.Shapes("ListBox1")
myListBox.ListFillRange = "A1:A10"