Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning Objects in VBA?

Tags:

clone

vba

Is there a generic way to clone objects in VBA? So that i could copy x to y instead of copying just the pointer?

  Dim x As New Class1
  Dim y As Class1

  x.Color = 1
  x.Height = 1

  Set y = x
  y.Color = 2

  Debug.Print "x.Color=" & x.Color & ", x.Height=" & x.Height

By generic i mean something like Set y = CloneObject(x) rather than having to create my own method for the class copying its properties one by one.

like image 809
Mark Nold Avatar asked Oct 20 '08 14:10

Mark Nold


1 Answers

Scott Whitlock has posted a fantastic answer to this problem on another question.

like image 119
MarkJ Avatar answered Sep 28 '22 07:09

MarkJ