2

我正在研究 Excel 宏。是否有一个选项可以让调试器像数组一样显示所有元素?

如果不是,那么在膨胀集合后,唯一的解决方法是将我的类对象存储在数组中吗?

4

3 回答 3

3

您可以使用debug.print输出并将其写入即时窗口并以这种方式绕过限制。

我几乎可以肯定没有办法增加这个限制,但也许其他人可以给出一个定义。对此作出回答。

于 2015-06-16T12:13:32.077 回答
3

答案似乎是否定的——但下面的 sub 可能会有所帮助。一个简单的实验表明它可以在调试模式下在即时窗口中使用:

Sub display(col As Collection)
    Dim i As Long
    Dim it As Variant
    Dim itType As String
    For i = 1 To col.Count
        it = col.Item(i)
        itType = TypeName(it)
        Debug.Print "Item " & i & " -- Value: " & it & " -- Type: " & itType
    Next i
End Sub
于 2015-06-16T13:38:33.540 回答
0

在我的情况下,集合的元素可以是数组。

约翰科尔曼的子可以改进以覆盖(至少一维)数组:

Sub display(col As Collection)
    Dim i As Long
    Dim it As Variant
    Dim itType As String
    For i = 1 To col.Count
        it = col.item(i)
        itType = TypeName(it)
        If Not IsArray(it) Then
            Debug.Print "Item " & i & " -- Value: " & it & " -- Type: " & itType
        Else
            Debug.Print "Item " & i & " -- Values: [" & Join(it, ", ") & "] -- Type: " & itType
        End If
    Next i
End Sub
于 2017-06-18T22:26:58.383 回答