gpt4 book ai didi

excel - 在 For-Next 循环 vba 期间按顺序显示控件

转载 作者:行者123 更新时间:2023-12-04 21:51:59 29 4
gpt4 key购买 nike

我有一个带有很多控件的 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

关于excel - 在 For-Next 循环 vba 期间按顺序显示控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52405443/

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