Visual Basic - 编译错误:无效的限定符

时间:2015-09-04 04:50:39

标签: excel vba excel-vba

我在Visual Basic中编写自定义Excel函数。当我运行该函数时,我在行Compile error: Invalid qualifier上的mondayArray上收到错误:For index = 0 To mondayArray.Length - 1。导致此错误的原因是什么?

Function SumHours(monday, tuesday, wednesday, thursday, friday, saturday, sunday)
    Dim mondayHours As Integer

    Dim mondayArray() As String
    Dim splitArray() As String

    SumHours = 0

    If monday <> "/" Then
        mondayArray = Split(monday, " ")

        For index = 0 To mondayArray.Length - 1
            splitArray = Split(mondayArray(index), "-")
        Next

    End If
End Function

1 个答案:

答案 0 :(得分:4)

.length不是数组的属性。使用LBound functionUBound function确定数组的范围(下边界和上边界)。

        For index = LBound(mondayArray) To UBound(mondayArray)

我相信你混淆了集合中的.length属性;例如HtmlElementCollection。