AddDiagram Method

Microsoft Excel Visual Basic

object that represents the new diagram.

expression.AddDiagram(Type, Left, Top, Width, Height)

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

Type   Required MsoDiagramType. The type of diagram.

MsoDiagramType can be one of these MsoDiagramType constants.
msoDiagramCycle A process diagram with a continuous cycle diagram type.
msoDiagramMixed A mixed diagram type.
msoDiagramOrgChart A hierarchical relationship diagram type.
msoDiagramPyramid A foundation based relationships diagram type.
msoDiagramRadial A diagram type showing relationships of a core element.
msoDiagramTarget A diagram type showing steps toward a goal.
msoDiagramVenn A diagram type showing areas of overlap between elements.

Left   Required Single. The position (in points) of the upper-left corner of the diagram relative to the upper-left corner of the worksheet.

Top   Required Single. The position (in points) of the upper-left top of the diagram relative to the upper-left corner of the worksheet.

Width   Required Single. The width of the diagram, in points.

Height   Required Single. The height of the diagram, in points.

Example

This example adds a pyramid diagram to the active sheet.

Sub CreatePyramidDiagram()

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

    'Add pyramid diagram to current document
    Set shpDiagram = ActiveSheet.Shapes.AddDiagram _
        (Type:=msoDiagramPyramid, Left:=10, _
        Top:=15, Width:=400, Height:=475)
    'Add first diagram node child to pyramid diagram
    Set dgnNode = shpDiagram.DiagramNode.Children.AddNode

    'Add three more diagram node children to the pyramid diagram
    For intCount = 1 To 3
        dgnNode.AddNode
    Next intCount

End Sub