MoveNode Method

Microsoft Excel Visual Basic

Show All

MoveNode Method

       

Moves a diagram node and any of its child nodes, within a diagram.

expression.MoveNode(pTargetNode, pos)

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

pTargetNode  Required DiagramNode object. The diagram node where the specified node will be moved.

pos  Required MsoRelativeNodePosition. The position to move the node, relative to TargetNode.

MsoRelativeNodePosition can be one of these MsoRelativeNodePosition constants.
msoAfterLastSibling
msoAfterNode
msoBeforeFirstSibling
msoBeforeNode

Example

The following example moves the second diagram node of a newly-created diagram to the last node.

Sub MoveDiagramNode()

    Dim dgnNode As DiagramNode
    Dim shpDiagram As Shape
    Dim intCount As Integer

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

    'Add four child nodes to the pyramid diagram
    Set dgnNode = shpDiagram.DiagramNode.Children.AddNode

    For intCount = 1 To 3
        dgnNode.AddNode
    Next intCount

    'Move the second node to after where the
    'fourth node is currently located.
    dgnNode.Diagram.Nodes(2).MoveNode _
        pTargetNode:=dgnNode.Diagram.Nodes(4), _
        Pos:=msoAfterLastSibling

End Sub