Reputation: 65
I have a Visual Basic for Applications (Excel) script I am trying to make, and part of that script involves filling an array with shape objects
Snippet as follows:
If rw3("PROCEDURE_ID_TRUE") = currPage Or rw3("PROCEDURE_ID_TRUE") = currPage Then
Dim ShapeObj2 As Visio.Shape
Set ShapeObj2 = AppVisio.Documents.Item("BASFLO_U.vssx").Masters.ItemU("Process").Shapes(1)
ShapeObj2.Name = Str(rw3("REGISTRATION_CONTROL_ID")) & "_Link"
ShapeObj2.NameU = Str(rw3("REGISTRATION_CONTROL_ID")) & "_Link"
ShapeObj2.Text = Str(rw3("REGISTRATION_CONTROL_ID")) & "_Link"
Set prevPageLinks(i) = ShapeObj2
i = i + 1
End If
Whenever I actually run this, it seems to be passing ShapeObj2 by reference. The entire array will always end up being whatever the last value of ShapeObj2 is.
How do I change this behavior? The Visio library does not allow for “New Visio.Shape”
Upvotes: 0
Views: 154
Reputation: 65
As it turns out, Visio has a .duplicate on their shape object which returns an exact copy of the object built in, and I just overlooked it.
The syntax I used was to just change
Set ShapeObj2 = AppVisio.Documents.Item("BASFLO_U.vssx").Masters.ItemU("Process").Shapes(1)
To
Set ShapeObj2 = AppVisio.Documents.Item("BASFLO_U.vssx").Masters.ItemU("Process").Shapes(1).Duplicate
This will obviously not work for everything, as VBA requires you to make a new object every time as it does not copy by value by default, but this is a functional solution for my needs.
Upvotes: 2