Microsoft Office Tutorials and References
In Depth Information
Figure A-8. The Diagram object and its children
seems to be a problem in adding or editing text for the nodes in a diagram. Frankly, I could not get
the feature to work at all. Even Microsoft's own example generates an error (whose message is
totally useless) on my PC. (I even tried recording a macro that changes the text and then replaying
the macro, but that too generates an error!) Here is the code:
Sub Example_Diagram()
Dim ws As Worksheet
Set ws = Application.ActiveSheet
Dim sh As Shape
Dim dia As Diagram
Dim node1 As DiagramNode
Dim node2Of1 As DiagramNode
Dim node3Of1 As DiagramNode
Dim node4Of2 As DiagramNode
Set sh = ws.Shapes.AddDiagram(msoDiagramOrgChart, 0, 0, 300, 300)
' Add first node. Note the odd syntax, since this node is not a
child.
Set node1 = sh.DiagramNode.Children.AddNode
' Add subsequent nodes
Set node2Of1 = node1.Children.AddNode
Set node3Of1 = node1.Children.AddNode
Set node4Of2 = node2Of1.Children.AddNode
' This works -- can read the text
MsgBox node1.TextShape.TextFrame.Characters.Text
' This does not work -- cannot set the text!!
node1.TextShape.TextFrame.Characters.Text = "Hamlet"
End Sub
Search JabSto ::




Custom Search