Microsoft KB Archive/294859

= XL2002: Cannot Record a Macro to Insert a Diagram =

Article ID: 294859

Article Last Modified on 1/31/2007

-

APPLIES TO


 * Microsoft Excel 2002 Standard Edition

-



This article was previously published under Q294859



SYMPTOMS
When you attempt to record a macro to insert a diagram, you receive the following error message:

You must select a shape.

No macro commands are recorded and the diagram is not inserted into your workbook.

NOTE: If you previously inserted a diagram into the workbook, you do not receive the error message; however, the macro commands are not recorded and the diagram is not inserted into your workbook.



CAUSE
This behavior occurs because the macro recording feature is not available for diagrams.



RESOLUTION
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.

