ReplaceNode Method

Microsoft Excel Visual Basic

expression.ReplaceNode(pTargetNode)

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

pTargetNode   Required DiagramNode object. The target diagram node to be replaced.

Example

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

Sub ReplaceNode()

    Dim nodRoot As DiagramNode
    Dim nodPrev As DiagramNode
    Dim shDiagram As Shape
    Dim intCount As Integer

    Set shDiagram = ActiveSheet.Shapes.AddDiagram _
        (Type:=msoDiagramRadial, Left:=10, Top:=15, _
        Width:=400, Height:=475)
    Set nodRoot = shDiagram.DiagramNode.Children.AddNode

    ' Add 3 child nodes to the root node.
    For intCount = 1 To 3
        nodRoot.Children.AddNode
    Next

    ' The second node will replace the last node.
    nodRoot.Children.Item(2).ReplaceNode pTargetNode:=nodRoot.Diagram.Nodes(4)

    ' The count will be 3 since the replaced node was deleted.
    MsgBox nodRoot.Diagram.Nodes.Count

End Sub