Change existing shape to a different shape

Z

Zachary

Is it possible to change a shape already on a page to a different shape,
keeping all other attributes like text, fill, etc. For example, I have a
decision block that I want to change to a process block.

Thanks,
 
J

John Goldsmith

Hello Zachary,

Have a look under the [File / Shapes / Flowchart /] Basic Flowchart Shapes
stencil and the shape named 'Flowchart shapes'. This is a single shape with
four geometries that you can select by right-clicking on the shape.

If you're looking for a more complex change then you'd need to do this with
code or, I think Paul Herber's 'Super Utilities' addon
(http://www.visio-utilities.sandrila.co.uk/) will do the job automatically.

Hope that helps.

Best regards

John


John Goldsmith
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk
 
K

Katrina

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
 
P

Paul Herber

Hello Zachary,

Have a look under the [File / Shapes / Flowchart /] Basic Flowchart Shapes
stencil and the shape named 'Flowchart shapes'. This is a single shape with
four geometries that you can select by right-clicking on the shape.

If you're looking for a more complex change then you'd need to do this with
code or, I think Paul Herber's 'Super Utilities' addon
(http://www.visio-utilities.sandrila.co.uk/) will do the job automatically.

Thanks John, and to the OP, I've just done an update with a new
feature and the shape substitute is now more reliable.
 
P

Paul Herber

You can also do it with the following macro:

Hi Katrina, I've been looking at your code with interest as one of my
utilities has this functionality ...
' 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

I'd totally failed to take this into account, Thank you.
'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

Um, are you sure this works correctly and doesn't miss some
connectors? As the connections are being deleted from shpOld then the
items in the collection move down, items get missed. I think your code
should iterate from FromConnects.Count down to 1.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top