Access to all the shapes of a diagram in .NET and in VBA

M

Marc Ridey

I'm trying to get reformat the shapes used in a diagram in a PowerPoint 2003
presentation.

If I try to access .GroupItems on a shape of type msoDiagram, I get an
Exception, both in VBA and in .NET C# that reads: This member can only be
accessed for a group

But ...

In the watches window, if I place the same object, I can navigate to the
GroupItems property and it contains correctly all the shapes of the diagram
and if I modify the properties of the shapes such as colors in the watches
window, then the diagram is changed.

Is there a way to work around the exception since the data is there to be
accessed?
 
S

Shyam Pillai

Marc,
Try:

Dim oShp As Shape
Dim oDgm As Diagram
Dim oNodeShp As Shape
Dim I As Integer
' Assuming that the selected shape is a diagram
Set oShp = ActiveWindow.Selection.ShapeRange(1)
Set oDgm = oShp.Diagram
For I = 1 To oDgm.Nodes.Count
' To get a reference to the shape of the current node
' Set oNodeShp = oDgm.Nodes(I).Shape

' To get the text of the current node
Debug.Print oDgm.Nodes(I).TextShape.TextFrame.TextRange.Text
Next
 
M

Marc Ridey

It would be great but there is a bug in PowerPoint and both the .Shape and
..TextShape properties of the DiagramNode clas return the Text shape of the
diagram. There is no access to the arrow shape of the diagram (in case of a
cycle diagram for example).

So the question remains: How do I get access to all the shapes that form the
diagram?
 
M

Marc Ridey

It's weird. I've spent the afternoon at work on this and I kept getting the
exception on the access to the GroupItems property : This memeber can only be
accessed for a Group.

I've tested both C#.Net using Interop and direct VBA Macro and both failed.
I'm now at home and tested you code and some of my tests and all work ... and
it's Office 2003 in both cases.

Thanks anyway. At least it shows me that it should work. Now I have to
figure out why in some cases it doesn't work.
 
M

Marc Ridey

Sometimes PowerPoint makes me want to cry.
Here's a new one:

I'm at home and testing the GroupItems property. Yes, I can access it fine
but the GruopItems.Count remains a constant. I have a Macro assigned to a
button on a toolbar with your exact code.

I insert a new diagram, select it, press the button and the 6 shapes are
accessed. Then I insert a new node, so there's 8 shapes. I press the button
and only 6 shapes are read. I insert more and more, still only 6 shapes are
read. .GroupItems.COunt remain equal to 6. I copy/delete/paste the diagram
and the GroupItems.Count value is reset to the right number of shapes in the
diagram.
 
S

Shyam Pillai

Marc,
I cannot reproduce it. The count changes to reflect any shapes added/removed
from the diagram.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top