Excel 在下一个循环vba期间按顺序显示控件

Excel 在下一个循环vba期间按顺序显示控件,excel,vba,for-loop,controls,Excel,Vba,For Loop,Controls,我有一个带有很多控件的VBA应用程序。 我想在For Next循环期间以读取顺序访问控件 ' Parcours des contrôles de l'userform For Each cCont In Me.Controls ' TypeName(cCont) MsgBox (cCont.Name) Next cCont 事实上,我想我正在访问创建日期 您知道我是否可以配置阅读顺序吗 谢谢一种方法是按照TabIndex属性对它们进行排序。将选项卡索引设置为所需的顺序,然后使

我有一个带有很多控件的VBA应用程序。 我想在For Next循环期间以读取顺序访问控件

' Parcours des contrôles de l'userform
For Each cCont In Me.Controls

   ' TypeName(cCont)
    MsgBox (cCont.Name)

Next cCont
事实上,我想我正在访问创建日期

您知道我是否可以配置阅读顺序吗


谢谢

一种方法是按照TabIndex属性对它们进行排序。将选项卡索引设置为所需的顺序,然后使用以下命令:

Private Sub test()

    Dim cCont As Control
    Dim i As Integer
    Dim maxIndex As Integer
    Dim controls As Object
    Dim key As Variant

    Set controls = CreateObject("Scripting.Dictionary")

    'Add controls to dictionary, key by tabindex property
    For Each cCont In Me.controls
        maxIndex = IIf(maxIndex < cCont.TabIndex, cCont.TabIndex, maxIndex)
        controls.Add cCont.TabIndex, cCont
    Next cCont

    'Get controls in order
    For i = 0 To maxIndex
        If controls.exists(i) Then
            MsgBox controls(i).Name
        End If
    Next i

End Sub
Private子测试()
作为控制的模糊控制
作为整数的Dim i
Dim maxIndex作为整数
将控件变暗为对象
变暗键作为变量
Set controls=CreateObject(“Scripting.Dictionary”)
'将控件添加到字典,按tabindex属性键
对于Me.controls中的每个cCont
maxIndex=IIf(maxIndex
您希望它们按阅读顺序排列的具体原因是什么?另外,我不确定你所说的阅读顺序是什么意思?我想这是关于顺序的。AFAIK每个循环的
只在添加控件时通过控件,您无法更改。感谢您的响应,事实上这是关于序列的。如果您确实需要按特定顺序处理它们,您可以在
中为每个
循环创建一个字典,对字典进行排序,然后按字典排序的顺序进行处理。