Solved

Excel Org Charts using VBA - Error Setting Text

Posted on 2007-04-03
2
1,406 Views
Last Modified: 2012-08-14
Hi All,

I'm trying to Build an org chart using Excel and VBA but can't even get the example from msdn to work.

Using Excel 2003 + 2007 File Convertor compatibilty pack (saving as .xlsm)


Example Code:

TextShape Property

Returns a Shape object representing the shape of the text box associated with a diagram node.
expression.TextShape

expression    Required. An expression that returns one of the objects in the Applies To list.

Example
The following example adds child nodes to a parent node, and displays text in the parent node indicating the number of child nodes created.


Sub CountChildNodes()

    Dim nodRoot As DiagramNode
    Dim shDiagram As Shape
    Dim intCount As Integer
    Dim shText As Shape

    Set shDiagram = ActiveSheet.Shapes.AddDiagram _
        (Type:=msoDiagramRadial, Left:=10, Top:=15, _
        Width:=400, Height:=475)
    Set nodRoot = shDiagram.DiagramNode.Children.AddNode

    ' Add 3 child nodes to the root node.
    For intCount = 1 To 3
        nodRoot.Children.AddNode
    Next

    ' Change text in node.
    For intCount = 1 To 4
        Set shText = shDiagram.DiagramNode.Children.Item(1).TextShape
        shText.TextFrame.Characters.Text = Str(intcount)
    Next intCount

End Sub
      


This line:         shText.TextFrame.Characters.Text = Str(intcount)
Casues: Run-time error '1004' Unable to set the Text property of the Characters Class



I just want to be able to set the text for a node after it has been created.

Thanks
0
Comment
Question by:Link-HRSystems
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 18842348
This is a known bug in Excel 2002, so I would have to guess that they probably haven't fixed it in 2003 based on what you say. The workaround, if you can call it that, is, believe it or not, to automate Word or Powerpoint!
See this MSKB article: http://support.microsoft.com/kb/317293
Regards,
Rory
0
 

Author Comment

by:Link-HRSystems
ID: 18844327
thanks, this has got me a little further so will give it a go.  
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question