Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To work around this issue, create a macro that inserts a diagram into your workbook. To do this, follow these steps:
- Open the workbook in which you want to store the macro.
- On the Tools menu, point to Macro, and then click Visual Basic Editor.
- In the Visual Basic Editor, click Module on the Insert menu.
- Type the following code in the Code window:
Sub InsertOrgChart()
Dim dgmNode As DiagramNode
Dim shpDiagram As Shape
Dim intCount As Integer
'Add organization chart diagram to current document.
Set shpDiagram = ActiveSheet.Shapes.AddDiagram _
(Type:=msoDiagramOrgChart, Left:=10, _
Top:=15, Width:=400, Height:=475)
'Add first diagram node to organization chart.
Set dgmNode = shpDiagram.DiagramNode.Children.AddNode
For intCount = 1 To 3
dgmNode.Children.AddNode
Next intCount
End Sub
The InsertOrgChart macro inserts an Organizational Chart diagram.