ControlFormat.ListIndex 运行时错误 Excel 2007

ControlFormat.ListIndex runtime error Excel 2007

我正在尝试研究工作表上列表框(表单控件)的问题。我想知道它在office 2007和2010及以后的版本中是否有不同的处理方式。

在Excel2007 年,在sheet1 中添加一个FormControl ListBox,并用一些随机值填充它。 确认 selection 类型设置为单个并且 运行 标准模块中的以下代码:

Sub TestListIndexExcel2007()
    Debug.Print ThisWorkbook.Worksheets(1).Shapes(1).ControlFormat.ListIndex
End Sub

直接 window 应该 return 列表框中 selected 项目的索引,到目前为止没问题。

现在将列表框的 selectiontype 设置为 Multi 或 Extend,但列表框中只有 select 1 项,并且再次 运行 上面的子项。我需要知道它是否会产生下面的错误,或者它是否仍然在 Excel 2007 中吐出一个列表索引。

Run-time Error '1004':

Unable to get the ListIndex property of the ListBox class

我会自己测试,但我无权访问 Office 2007。

不,不是。您将遇到的第一个错误是 438 错误,因为 Shape 没有 FormControl 属性。如果您将其替换为 ControlFormat 那么是的,您将收到 1004 错误。