Diagram Property

Microsoft Excel Visual Basic

object representing a diagram.

expression.Diagram

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

Example

In this example, an organization chart diagram is added to the active worksheet. Microsoft Excel then displays a message with the number of nodes added to the diagram.

Sub UseDiagram()

    Dim wksOne As Worksheet
    Dim shpOrgChart As Shape
    
    Set wksOne = ActiveSheet
    
    'Add organization chart diagram to current worksheet.
    Set shpOrgChart = ActiveSheet.Shapes.AddDiagram _
        (Type:=msoDiagramOrgChart, _
        Top:=10, Left:=15, Width:=400, Height:=475)
        
    'Add first node to organization chart.
    shpOrgChart.DiagramNode.Children.AddNode
    
    'Notify user of the number of nodes added to the diagram.
    MsgBox shpOrgChart.Diagram.Nodes.Count

End Sub