ReplaceNode Method

Microsoft Word Visual Basic

ReplaceNode Method

       

Replaces a target diagram node with the source diagram node. The target diagram node is deleted, and the source diagram node, including any of its child nodes, are moved to where the target diagram node was.

expression.ReplaceNode(TargetNode)

expression   Required. An expression that returns a DiagramNode object.

TargetNode  Required DiagramNode object. The diagram node to be replaced.

Example

The following example replaces the fourth diagram node of a newly-created diagram with the second node.

Sub Replace()
    Dim dgnNode As DiagramNode
    Dim shpDiagram As Shape
    Dim intCount As Integer

    'Add pyramid diagram to current document
    Set shpDiagram = ThisDocument.Shapes.AddDiagram _
        (Type:=msoDiagramPyramid, Left:=10, _
        Top:=15, Width:=400, Height:=475)

    'Add first child node to diagram
    Set dgnNode = shpDiagram.DiagramNode.Children.AddNode

    'Add three more child nodes
    For intCount = 1 To 3
        dgnNode.AddNode
    Next intCount

    'Replace fourth node with the second node
    dgnNode.Diagram.Nodes(2).ReplaceNode _
        TargetNode:=dgnNode.Diagram.Nodes(4)

End Sub