gpt4 book ai didi

excel - 无法在 Excel VBA 用户窗体中设置多列列表框的选定属性

转载 作者:行者123 更新时间:2023-12-04 22:29:45 26 4
gpt4 key购买 nike

我无法检查多列用户表单列表框中的项目。行lstPreConditionLogic.Selected(lstPreConditionLogic.ListCount) = True生成以下错误:

Run-time error '380': Could not set the Selected property. Invalid property value



我尝试将值设置为 -1 , checked但它没有用。

VBA代码
Private Function FillPreConditionLogicList()
Dim varTemp As Variant
Dim intLoop As Integer
Dim strExpression As String
Dim PreConditionLogic As clsPreConditionLogic

With lstPreConditionLogic
.ColumnCount = 3
.ListStyle = fmListStyleOption
.MultiSelect = fmMultiSelectMulti
strExpression = TrimBlank(shtExpressionEditor.Range("rngExpText").Offset(, 1).Value)
For intLoop = 0 To mDicPreConditionLogic.Count - 1
Set PreConditionLogic = mDicPreConditionLogic.Items(intLoop)
.AddItem
.List(intLoop, 0) = PreConditionLogic.Name
.List(intLoop, 1) = PreConditionLogic.StartEnclosure
.List(intLoop, 2) = PreConditionLogic.EndEnclosure
varTemp = GetEnclosedString(strExpression, PreConditionLogic.StartEnclosure, PreConditionLogic.EndEnclosure)
If varTemp <> "" Then
lstPreConditionLogic.Selected(lstPreConditionLogic.ListCount) = True '//Gives Error
strExpression = varTemp
End If
Next
End With
End Function

最佳答案

您必须减去 -1来自您的.ListCount

lstPreConditionLogic.Selected(lstPreConditionLogic.ListCount - 1) = True

因为列表索引统计在 0但例如如果 ListCount = 5那么这5个条目的索引是 0 , 1 , 2 , 3 , 4这意味着最后一个有效索引是 .ListCount - 1 .

关于excel - 无法在 Excel VBA 用户窗体中设置多列列表框的选定属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54212202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com