XL2002: Cannot Record a Macro to Insert a Diagram (294859)
The information in this article applies to:
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.
RESOLUTIONMicrosoft 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.
REFERENCES
For more information about creating a macro to insert a diagram, from the Visual Basic Editor, click the
Office Assistant, type diagram property, click Search, and
then click to view "Diagram Property."
Modification Type: | Minor | Last Reviewed: | 1/6/2006 |
---|
Keywords: | kberrmsg kbprb KB294859 |
---|
|