1

I'm creating a PowerPoint AddIn, which is supposed to read information from an external file and integrate that information into the current slide which contains shapes, mostly textbox shapes and connector shapes connecting the text boxes. Each connector is located within a group, containing the connector shape and a textbox, with acts as a label for the connector. The following image depicts this scenario.

enter image description here

My task at hand involves accessing properties of connector shapes contained within groups as described above, namely BeginConnectedShape and EndConnectedShape. Here's some code which is supposed to do just that:

Shape groupShape = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange[1];
//check if groupshape actually is a group
if (groupShape.Type == Microsoft.Office.Core.MsoShapeType.msoGroup) {
    //iterate over all elements within groupShape
    foreach (Shape childShape in groupShape.GroupItems)
    {
        if (childShape.Connector == Microsoft.Office.Core.MsoTriState.msoTrue)
        {
            //if the shape is a connector, retrieve source and target of the connector
            Shape source = childShape.ConnectorFormat.BeginConnectedShape;
            Shape target = childShape.ConnectorFormat.EndConnectedShape;

            //Do something with source and target.
        }
    }
}

Running this code while having a group containing a properly connected connector shape (that is, both ends are connected to anchor points of other shapes) selected yields the following exception.

System.Runtime.InteropServices.COMException wurde nicht von Benutzercode behandelt.
  HResult=-2147418113
  Message=Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
  Source=HandoverAddin
  ErrorCode=-2147418113
  StackTrace:
       at Microsoft.Office.Interop.PowerPoint.ConnectorFormat.get_BeginConnectedShape()
       at MyAddin.Ribbon.button1_Click(Object sender, RibbonControlEventArgs e) in Ribbon.cs:line 56
       at Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ControlActionRaise(IRibbonControl control)
       at Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ButtonClickCallback(RibbonComponentImpl component, Object[] args)
       at Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.Invoke(RibbonComponentCallback callback, Object[] args)
       at Microsoft.Office.Tools.Ribbon.RibbonMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.System.Reflection.IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
  InnerException:

This exception is raised when executing childShape.ConnectorFormat.BeginConnectedShape. childShape.ConnectorFormat.EndConnectedShape raises this exception as well. Other operations within ConnectorFormat work fine (i.e. BeginDisconnect successfully disconnects the start of the connector).

shape.ConnectorFormat.BeginConnectedShape works fine, if the connector is not contained within a group. In my case tough, connectors and associated labels have to be grouped together.

I've also observed that accessing BeginConnectedShape on a connector with a disconnected start raises an UnauthorizedAccessException, regardless of whether that connector is contained within a group or not. This seems to be expected behavior.

The exception listed above seems to be some sort of internal exception which is not supposed to get raised under normal circumstances. Therefore, I've checked for any available updates, but none were found for Office 2010 and Visual Studio 2010 Professional.

Any help, possible fixes or workarounds on this issue are greatly appreciated.


Edit: Implementing the same functionality using VBA also results in an error with code 8000FFFF (same as above).

  • That error message merely rates the quality of the error reporting. You ought to check the BeginConnected and EndConnected properties to make sure it they are actually connected. – Hans Passant Sep 29 '14 at 15:11
  • BeginConnected and EndConnected both return true in this example. –  Sep 29 '14 at 15:33
  • My tests show that this is a genuine bug in PowerPoint. – dotNET Jun 29 '17 at 13:30

1 Answers1

0

Here's a crude VBA version of this that might help:

It's essentially the same as yours, I think, except for the added test:

If osh.Connector

Without that, it raised errors because it's looking at each shape in the group, but only the connector has the .ConnectorFormat and its associated properties.

Dim groupshape As Shape
Dim oSh As Shape
Dim oBgnShape As Shape
Dim oEndShape As Shape

Set groupshape = ActiveWindow.Selection.ShapeRange(1)

If groupshape.Type = msoGroup Then
For Each oSh In groupshape.GroupItems
    **If oSh.Connector Then**
        Set oBgnShape = oSh.ConnectorFormat.BeginConnectedShape
        Debug.Print oBgnShape.Left
        Set oEndShape = oSh.ConnectorFormat.EndConnectedShape
    End If
Next

End If
Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34