'Copy Or Reference assignment of Class Module

I'm currently working on a task where I am just creating stub modules and stub Class modules for an excel spreadsheet that will loop through specific cells that contain an Excel vba macro name. I am trying to either copy or reference a class module. Either solution works since I am just creating stubs. The current goal is to just get some strings within the macros that are executed. Unfortunately, I have a restriction where I am unable to modify the vba code that is provided to me already.

Below is a simplified version of what I am trying to achieve.

' Class1 code
Public x As Integer

Private Sub Class_Initialize()
End Sub
Private Sub Class_Terminate()
End Sub

' Module1 Code

Function Copy_Class() As Class1
    Set Copy_Class = New Class1
    Copy_Class.x = 231
End Function

Sub testing_class_copy_or_reference()
    Dim orig_class As New Class1

    orig_class = Copy_Class ' <- Fails here
    Debug.Print orig_class.x
End Sub

I do have a workaround fix and that is to do Set orig_class = Copy_Class but, again, the goal is to not have to modify the provided vba macros.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source