Microsoft KB Archive/317293

= You cannot set text in a diagram node shape through Visual Basic for Applications in Excel 2003 or in Excel 2002 =

Article ID: 317293

Article Last Modified on 7/20/2007

-

APPLIES TO


 * Microsoft Excel 2002 Standard Edition
 * Microsoft Office Excel 2003

-



This article was previously published under Q317293





SYMPTOMS
In Excel 2003 and Excel 2002, it is not possible to programmatically set the text in a diagram node shape through Visual Basic for Applications (VBA). If you try to set the text in a diagram node shape programmatically, you may receive the following error message:

Run-time error '1004': Unable to set the Text property of the Characters class



WORKAROUND
To work around this issue, design your macro to automate Microsoft Word or Microsoft PowerPoint in this manner, to create the diagram in the automated program, and then to copy it into the Excel workbook.

The following sample macro creates an organization chart diagram with four nodes in Word, sets the text for each node, and then copies the diagram to an Excel workbook: Sub TextShapeAddText '/ Dim Integer(s) Dim i As Integer '/ Dim Object(s) Dim oCurShape As Object Dim oCurShapeNode As Object Dim oCurDiagNode As Object Dim oCurWorkApplObj As Object '/ Create a Word application object. Set oCurWorkApplObj = CreateObject(&quot;Word.Application&quot;) '/ Open a new Word document. Workbooks.Add oCurWorkApplObj.Documents.Add '/ Add a shape. Set oCurShape = oCurWorkApplObj.ActiveDocument.Shapes.AddDiagram _ (msoDiagramPyramid, 10, 15, 400, 475)

'/ Add a node. Set oCurShapeNode = oCurShape.DiagramNode.Children.AddNode '/ Add child nodes. For i = 1 To 3 oCurShapeNode.AddNode Next

'/ Add text to the child nodes. For i = 1 To 4 'Inserting text in each node oCurShapeNode.Diagram.Nodes.Item(i) _ .TextShape.TextFrame.TextRange.Text = Str(i) Next '/ Copy the shape to Excel. oCurWorkApplObj.ActiveDocument.Shapes.SelectAll oCurWorkApplObj.Selection.Copy ActiveSheet.Paste '/ Quit Word. oCurWorkApplObj.Quit saveChanges:=False

End Sub



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

Additional query words: XL2002 XL2003

Keywords: kbbug kbofficexppresp2fix kbpending KB317293

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.