VBA 调试器仅显示集合的 256 个元素

VBA debugger shows only 256 elements of a collection

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

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

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

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

答案似乎是否定的——但以下内容可能会有所帮助。一个简单的实验表明,它可以在调试模式下立即使用window:

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

在我的例子中,集合的元素可以是数组。

John Coleman 的 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)
        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