ReplaceNode Method

Microsoft PowerPoint Visual Basic

expression.ReplaceNode(TargetNode)

expression    Required. An expression that returns one of the objects in the Applies To list.

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

Example

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

Sub ReplaceLastNode()

    Dim dgnNode As DiagramNode
    Dim shpRadial As Shape
    Dim intNodes As Integer

    'Adds radial diagram and root node
    Set shpRadial = ActivePresentation.Slides(1).Shapes.AddDiagram _
        (Type:=msoDiagramRadial, Left:=10, Top:=15, _
        Width:=400, Height:=475)
    Set dgnNode = shpRadial.DiagramNode.Children.AddNode

    'Adds three additional child nodes
    For intNodes = 1 To 3
        dgnNode.Children.AddNode
    Next intNodes

    'Displays the number of nodes in the diagram
    MsgBox "The number of nodes in the diagram : " & _
         dgnNode.Diagram.Nodes.Count

    'Second node replaces the last node.
    dgnNode.Diagram.Nodes(2).ReplaceNode _
        TargetNode:=dgnNode.Diagram.Nodes(4)

    'Node count is three because the replaced node was deleted
    MsgBox "The number of nodes in the diagram : " & _
        dgnNode.Diagram.Nodes.Count

End Sub