Private Function GetActiveCtrlUbound() As Integer Dim x As VB.Control Dim MaxIndex As Integer
For Each x In Me.Controls If VBA.VarType(VBA.CallByName(Me, x.Name, VbGet)) = vbObject Then '控件数组 If x.Name = Me.ActiveControl.Name Then If MaxIndex < x.Index Then MaxIndex = x.Index End If End If Next GetActiveCtrlUbound = MaxIndex End Function
Dim x As VB.Control
Dim MaxIndex As Integer
For Each x In Me.Controls
If VBA.VarType(VBA.CallByName(Me, x.Name, VbGet)) = vbObject Then '控件数组
If x.Name = Me.ActiveControl.Name Then
If MaxIndex < x.Index Then MaxIndex = x.Index
End If
End If
Next
GetActiveCtrlUbound = MaxIndex
End Function
谢谢,虽然For Each比较耗资源,但好像也没更好的办法了。