I am trying to assign a merged shape to a new layer. I have tried to assign the initial shape but it didn't work. This is part of my coding so far.
Dim vsoLayer As Visio.Layer
Dim vsoLayers As Visio.Layers
Set vsoLayers = ActivePage.Layers
Set vsoLayer = vsoLayers.Add("Layer1")
Dim vsoShapeA1 As Visio.shape
Set vsoShapeA1 = ActivePage.DrawRectangle(1, 5, 5, 1)
vsoShapeA1.Cells("Fillforegnd").Formula = "RGB(215,135,131)"
vsoShapeA1.BringToFront
Dim vsoShapeA2 As Visio.shape
Set vsoShapeA2 = ActivePage.DrawRectangle(2, 6, 6, 1)
vsoShapeA2.Cells("Fillforegnd").Formula = "RGB(215,135,131)"
vsoShapeA2.BringToFront
ActiveWindow.DeselectAll
vsoSelection.Select vsoShapeA1, visSelect
vsoSelection.Select vsoShapeA2, visSelect
vsoSelection.Union
vsoLayer.Add (?)......
Then I am stuck to assign the merged shape to a layer. Needing help. Thanks.
CodePudding user response:
Union will remove the existing shapes and create a new shape. The new shape will be the most recent shape in the page's Shapes collection. You can use the to get a reference to the new shape and add it to the layer:
Set vsoNewShape = ActivePage.Shapes.Item(ActivePage.Shapes.Count)
vsoLayer.Add vsoNewShape, 0