SwapNode Method

Microsoft Excel Visual Basic

expression.SwapNode(pTargetNode, swapChildren)

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.

swapChildren   Optional Boolean. The child nodes of the target and source nodes being swapped. Any child diagram nodes are moved along with their corresponding root nodes. Default is True, which swaps the child nodes.

Example

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

Sub SwapNode()

    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

    ' Swap the second node with the fourth node.
    nodRoot.Children.Item(2).SwapNode _
        pTargetNode:=nodRoot.Diagram.Nodes(4), _
        swapChildren:=True

End Sub