LastChild Property

Returns a DiagramNode object that represents the last child node of a parent node.


expression Required. An expression that returns a DiagramNodeChildren object.


Use the FirstChild property to access the first child node in a diagram. Use the Root property to access the parent node in a diagram.


This example adds an organization chart diagram to the current document, adds three nodes, and assigns the first and last diagram nodes to variables.

Sub FirstChild()
    Dim shpDiagram As Shape
    Dim dgnRoot As DiagramNode
    Dim dgnFirstChild As DiagramNode
    Dim dgnLastChild As DiagramNode
    Dim intCount As Integer

    'Add organization chart to the current document
    Set shpDiagram = ThisDocument.Shapes.AddDiagram _
        (Type:=msoDiagramOrgChart, Left:=10, _
        Top:=15, Width:=400, Height:=475)

    'Add the first diagram node to the organization chart
    Set dgnRoot = shpDiagram.DiagramNode.Children.AddNode

    'Add three diagram child nodes under the first diagram node
    For intCount = 1 To 3

    'Assign the first and last child nodes to variables
    Set dgnFirstChild = dgnRoot.Children.FirstChild
    Set dgnLastChild = dgnRoot.Children.LastChild
End Sub

Applies to | DiagramNodeChildren Collection | XMLNode Object