CloneNode Method

Microsoft Excel Visual Basic

Show All

CloneNode Method

       

Clones a diagram node. Returns a DiagramNode object representing the cloned node.

expression.CloneNode(copyChildren, pTargetNode, pos)

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

copyChildren  Required Boolean. True to clone the diagram nodes children as well.

pTargetNode  Optional DiagramNode object. An expression that returns a DiagramNode object that represents the node where the new node will be placed.

pos  Optional MsoRelativeNodePosition. If pTargetNode is specified, indicates where the node will be added relative to pTargetNode.

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

Example

The following example creates a diagram and clones the newest-created node.

Sub CloneANode()

    Dim nodRoot As DiagramNode
    Dim shpDiagram As Shape
    Dim nodFourthNode As DiagramNode
    Dim nodDuplicate As DiagramNode
    Dim intCount As Integer

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

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

    Set nodFourthNode = nodRoot.Children.Item(4)

    'Clone the most recently created child node
    Set nodDuplicate = nodRoot.Children.Item(1).CloneNode(copyChildren:=True, _
        pTargetNode:=nodFourthNode, pos:=msoAfterNode)

End Sub