title: Can You Add a Class to a Class Property VBA
body: <p>So I have two Class modules, ClassA and ClassB, and a sub in a module in which I try to add an object from Class B to a property of an object in ClassA.</p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/office/gg264263.aspx" rel="nofollow noreferrer">According to the VBE Glossary</a>, classes are objects and the property set statement can add object types, so it seems like this should be possible. However, when I run the test sub I get an "object variable or with block variable not set" error</p>
  
  <p>The Sub:</p>
  
  <pre><code>Sub test()
  
  Dim Class_A_Object As ClassA
  Dim Class_B_Object As ClassB
  
  Set Class_A_Object = New ClassA
  Set Class_B_Object = New ClassB
  
  Class_B_Object.Class_B_Property = 42
  Class_A_Object.Class_A_Property = Class_B_Object
  
  End Sub
  </code></pre>
  
  <p>ClassA:</p>
  
  <pre><code>Private a_Class_A_Property As Object
  
  Public Property Set Class_A_Property(pClass_A_Property As Object)
      a_ClassA_Property = pClass_A_Property
  End Property
  
  Public Property Get Class_A_Property() As Object
      Class_A_Property = a_Class_A_Property
  End Property
  </code></pre>
  
  <p>Class B:</p>
  
  <pre><code>Private b_Class_B_Property As Integer
  
  Public Property Let Class_B_Property(pClass_B_Property As Integer)
      b_Class_B_Property = pClass_B_Property
  End Property
  
  Public Property Get Class_B_Property() As Integer
      Class_B_Property = b_Class_B_Property
  End Property
  </code></pre>