Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2002: Cannot Record a Macro to Insert a Diagram


View products that this article applies to.

This article was previously published under Q294859

↑ Back to the top


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.

↑ Back to the top


Cause

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

↑ Back to the top


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:
  1. Open the workbook in which you want to store the macro.
  2. On the Tools menu, point to Macro, and then click Visual Basic Editor.
  3. In the Visual Basic Editor, click Module on the Insert menu.
  4. 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.

↑ Back to the top


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

↑ Back to the top


Keywords: KB294859, kbprb, kberrmsg

↑ Back to the top

Article Info
Article ID : 294859
Revision : 4
Created on : 1/31/2007
Published on : 1/31/2007
Exists online : False
Views : 210