LastChild Property

Microsoft Excel Visual Basic

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

expression.LastChild

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

Example

The following example adds a child node to the last child diagram node in a newly-created diagram.

Sub LastChildNode()

    Dim nodDiagram As DiagramNode
    Dim nodLast As DiagramNode
    Dim shDiagram As Shape
    Dim intCount As Integer

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

    ' Add three diagram child nodes under the first diagram node
    For intCount = 1 To 3
        nodDiagram.Children.AddNode
    Next intCount

    ' Assign the last child node to a variable
    Set nodLast = nodDiagram.Children.LastChild

    ' Add a node to the last child node.
    nodLast.Children.AddNode

End Sub