excel - excel vba listbox additem
问题描述
I am running office 365 home on windows 10. I am programming Excel using VBA. I have a data range in a worksheet row. I want the user to be able to select one item from this row of data. I am trying to populate ListBox or ComboBox with dta from the range row. Having read MS vba.reference documentation I decided to get my range data into an array and use listbox = myarray() and got "Object does not support this method or property." I tried looping through my data range and putting each item in using listbox.additem (mydata()) with the same result. On examination of the listbox prperties AddItem is not there. Seems they have been withdrawn or maybe never existed for Excel VBA. Any suggestions?
解决方案
如果您使用的是 Additem,那么您应该只添加一个项目而不是一个数组。如果要使用数组,则必须使用 List 并且数组应该是一维的
MyListBox.List=MyOneDArray
就我个人而言,我从不使用 .List 和带有 Listboxes 的数组,因为我发现在某些情况下它不能按预期工作。
推荐阅读
- angular - SyntaxError:JSON中的意外标记o在角度位置1
- powershell - 如何在导出到 CSV 文件时重命名属性?
- javascript - 有没有办法使用以前的 Chrome 版本?
- python-3.x - 使用列表更新字典时出现 ValueError
- c# - 使用 HttpContext cookie 有没有办法允许在浏览器关闭时删除它以及有一个到期时间?
- android - 如何在 AOSP 源代码中添加预构建的应用程序(系统应用程序)
- php - 跨所有相关数组键同步数组值
- docker - kind cluster - 如何查看已加载的 docker-images?
- python - 在什么情况下看起来像 python 内存泄漏的问题不是泄漏?
- python - SqlAlchemy 为 ColumnClause 分配不同的列名