ControlFormat.ListIndex runtime error Excel 2007

旧巷老猫 提交于 2019-12-24 16:09:38

问题


I'm trying to research an issue with a listbox (Form Control) on a worksheet. I need to know if it is handled different in office 2007 and 2010 and later.

In Excel 2007, add a FormControl ListBox to sheet1, and fill it with some random values. Verify that the selection type is set to single and run the following code in a standard module:

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

The immediate window should return the index of the selected item in the listbox, so far no problem.

Now set the selectiontype of the listbox to Multi or Extend but only select 1 item in the listbox and run the sub above again. I need to know if it generates the error below or if it still spits out a listindex in Excel 2007.

Run-time Error '1004':

Unable to get the ListIndex property of the ListBox class

I would test this myself but I don't have access to Office 2007.


回答1:


No it doesn't. The first error you will get is a 438 error since a Shape doesn't have a FormControl property. If you replace that with ControlFormat then yes you'll get a 1004 error.



来源:https://stackoverflow.com/questions/34853498/controlformat-listindex-runtime-error-excel-2007

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!