VBA'参数不可选'错误

时间:2018-02-12 17:57:48

标签: excel vba excel-vba

所以我有这个代码循环遍历列表框中的选定项目并将它们添加到集合中。由于某种原因,它会在注释掉的行中抛出编译错误“Argument Not Optional”,该行尝试将所选项添加到Collection中。

但是,添加“test”的行正常。

我知道这是一个可选参数,因为它甚至让我使用Intellisense popup来使用“Add”。所以我很困惑。

    If optPaste = True Then
        'Paste Code
    Else
        'Read In Selection
            Dim tempArray As Variant
            Dim i As Integer
            Dim colSelected As Collection
            Set colSelected = New Collection
            colSelected.Add ("test")

                For i = 0 To Me.ListBox1.ListCount - 1
                    If Me.ListBox1.Selected(i) Then
                        tempArray = Split(Me.ListBox1.List(i), " - ")
                       ' colSelected.Add = tempArray(1)
                    End If
                Next i
                MsgBox (colSelected(1))
    End If

0 个答案:

没有答案
相关问题