UBound(Me.ActiveControl)提示“缺少数组”Me.ActiveControl.UBound 提示“对象不支持该属性或方法”

解决方案 »

  1.   

    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
      

  2.   


    谢谢,虽然For Each比较耗资源,但好像也没更好的办法了。