title: Better way to iterate over custom-object class Excel VBA
body: <p>I'm trying to figure out a way to iterate over custom-objects contained in (a dictionary) other custom objects without having to use 'set' every time.</p>
  
  <p>my goal would be able to write straight:</p>
  
  <pre><code>For Each Person In Family.GetMembers
      test= Person.Age
  Next Person
  </code></pre>
  
  <p>but the above gives me a <code>object required</code> error. However, I want to avoid something like</p>
  
  <pre><code>for each name in family.keys
     set Person = Family.GetMember(name) 
     test= Person.Age
  next name
  </code></pre>
  
  <p>class object cperson</p>
  
  <pre><code>Option Explicit
  Private pName As String
  Private pAge As Integer
  Public Property Let name(name As String):
      pName = name
  End Property
  Public Property Get name() As String
      name = pName
  End Property
  Public Property Let Age(Age As Integer):
      pAge = Age
  End Property
  Public Property Get Age() As Integer
      Age = pAge
  End Property
  </code></pre>
  
  <p>class object cfamily</p>
  
  <pre><code>Option Explicit
  Private pFamily As Object
  Private pName As String
  Private Sub Class_Initialize()
      Set pFamily = CreateObject("Scripting.Dictionary")
  End Sub
  Private Sub Class_Terminate()
      Set pFamily = Nothing
  End Sub
  Public Sub Add(Person As CPerson)
      If pFamily.exists(Person.name) Then
          pFamily.Remove Person.name
          pFamily.Add Person.name, Person
      Else
          pFamily.Add Person.name, Person
      End If
  End Sub
  Public Property Get GetMember(name As Variant) As CPerson:
      Set GetMember = pFamily(name)
  End Property
  Public Property Let name(name As String):
      pName = name
  End Property
  Public Property Get name() As String
      name = pName
  End Property
  Public Property Get GetMembers() As Variant
      Dim tmpArray() As Variant, Person As CPerson, i As Integer, name As Variant
      ReDim tmpArray(pFamily.Count)
      i = 1
      For Each name In pFamily.keys
          Set Person = pFamily(name)
          Set tmpArray(i) = Person
          i=i+1
      Next name
      GetMembers = tmpArray
  End Property
  </code></pre>