You can also do it with the following macro:
ublic Sub SwapShapesMultiple()
Dim shpNew As Visio.Shape
' Dim i As Integer
If Visio.ActiveWindow.Selection.Count < 2 Then
'Abort if there are not 2 shapes selected
MsgBox "You must select at least 2 shapes. First select the New
shape, then one or more Old shapes to be replaced by the new shape",
vbOKOnly, "Select at least 2 shapes"
Exit Sub
Else
' New shape is first item selected.
Set shpNew = Visio.ActiveWindow.Selection.Item(1)
'Abort if shape is 1-dimensional (connector line)
If shpNew.OneD Then
MsgBox "New shape (first items selected) is a connector line",
vbOKOnly, "New shape is a connector"
Exit Sub
End If
' Save a copy of the current "New" object.
' The first time we do a "swap", we'll use the original "New" shape.
' For any of the [optional] remaining swaps, we do a "Paste" and make
' that the "New" object.
shpNew.Copy
End If
' Cache references to old shapes.
Dim shpOldShapes() As Visio.Shape
ReDim shpOldShapes(Visio.ActiveWindow.Selection.Count - 2) As Shape
For shpIdx = 2 To Visio.ActiveWindow.Selection.Count
Set shpOldShapes(shpIdx - 2) =
Visio.ActiveWindow.Selection.Item(shpIdx)
Next shpIdx
Visio.ActiveWindow.DeselectAll
' Disable auto-layout/reroute while moving shapes to prevent the
' layout engine from automatically moving shapes (to avoid
collisions).
Dim bAutoLayout As Boolean
bAutoLayout = Application.AutoLayout
Application.AutoLayout = False
For shpIdx = LBound(shpOldShapes) To UBound(shpOldShapes)
Dim shpOld As Visio.Shape
Set shpOld = shpOldShapes(shpIdx)
' Debug.Print "Old shape #", shpIdx, " == ", shpOld.Text
'Abort if shape is 1-dimensional (connector line)
If shpOld.OneD Then
' Restore auto routing!
Application.AutoLayout = bAutoLayout
MsgBox "Old shape # " & shpIdx & " (second through last items
selected) is a connector line", vbOKOnly, "Shape is a connector"
Exit Sub
End If
' Restore the original "New" shape from the clipboard.
If shpIdx > 0 Then
Visio.ActiveWindow.Paste
Set shpNew = Visio.ActiveWindow.Selection.Item(1)
End If
'Change connections to new shape
Dim cnx As Visio.Connect
For Each cnx In shpOld.FromConnects
cnx.FromCell.GlueTo shpNew.CellsSRC(cnx.ToCell.Section,
cnx.ToCell.Row, cnx.ToCell.Column)
Next cnx
'Set the text
shpNew.Text = shpOld.Text
'Set the position of the new shape
shpNew.Cells("PinX").Formula = shpOld.Cells("PinX").Formula
shpNew.Cells("PinY").Formula = shpOld.Cells("PinY").Formula
'Set the size of the new shape
shpNew.Cells("Width").Formula = shpOld.Cells("Width").Formula
shpNew.Cells("Height").Formula = shpOld.Cells("Height").Formula
'Delete the old shape
shpOld.Delete
Next shpIdx
' Restore auto routing
Application.AutoLayout = bAutoLayout
End Sub