运行-从 FormControl ListBox 检索值时出错
Run-time error when retrieving value from FormControl ListBox
我将名称为 ListBox2
的 FormControl
ListBox
添加到 Excel 工作表,并将宏 RectangleRoundedCorners3_Click
分配给形状。现在我想将列表框的第一项打印到单元格 A1 中:
Sub RectangleRoundedCorners3_Click()
ActiveSheet.Range("A1").Value = ActiveSheet.ListBox1.List(0)
End Sub
我收到以下错误:
Run-time error '438':
Object doesn't support this property or method
我真的不明白为什么会这样。如果我使用 ActiveX Controls
ListBox
完全相同的代码工作得很好。
尝试:
ActiveSheet.Range("A1").Value = Activesheet.ListBoxes("ListBox2").List(1)
注意:引用 ActiveSheet
并不是引用 sheet 的最佳方式。在这里查看 this post 以了解更多信息。
可以在站点 Complete guide to Excel VBA Form Control ListBoxes 上找到有关 FormControl ListBoxes
使用多种方法的有用概述。 - 根据乔纳斯的评论进行编辑:-)
我将名称为 ListBox2
的 FormControl
ListBox
添加到 Excel 工作表,并将宏 RectangleRoundedCorners3_Click
分配给形状。现在我想将列表框的第一项打印到单元格 A1 中:
Sub RectangleRoundedCorners3_Click()
ActiveSheet.Range("A1").Value = ActiveSheet.ListBox1.List(0)
End Sub
我收到以下错误:
Run-time error '438':
Object doesn't support this property or method
我真的不明白为什么会这样。如果我使用 ActiveX Controls
ListBox
完全相同的代码工作得很好。
尝试:
ActiveSheet.Range("A1").Value = Activesheet.ListBoxes("ListBox2").List(1)
注意:引用 ActiveSheet
并不是引用 sheet 的最佳方式。在这里查看 this post 以了解更多信息。
可以在站点 Complete guide to Excel VBA Form Control ListBoxes 上找到有关 FormControl ListBoxes
使用多种方法的有用概述。 - 根据乔纳斯的评论进行编辑:-)