VBA debugger shows only 256 elements of a collection

4.7k views Asked by At

I'm working on an Excel macro. Is there an option that the debugger shows all elements like it does with an array?

If not, is the only workaround the storage of my classobjects in an array after inflating the collection?

3

There are 3 answers

5
rohrl77 On BEST ANSWER

You could use debug.print and write the output into the immediate window and bypass the limit that way.

I am almost certain that there is no way to increase that limit, but maybe someone else can give a def. answer on that.

2
John Coleman On

The answer seems to be no -- but the following sub might help. A simple experiment shows that it can be used in the immediate window while in debug mode:

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
1
nkatsar On

In my case the elements of the collection could be arrays.

John Coleman's sub could be improved to cover (at least one-dimensional) arrays as:

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