Cannot ungroup a PowerPoint SmartArt Shape

家住魔仙堡 提交于 2019-12-12 01:58:39

问题


I try to ungroup a SmartArt shape from code, but it always causes an error: "This member can only be accessed for a group".

However, it's working, if I right click on the SmartArt shape, and ungroup it.

How can I fix this?

My code is:

public void CreateSmartArt(PowerPoint.Shapes allShapes)

{

     PowerPoint.Shape smartartShape = allShapes.AddSmartArt(IttPowerPoint.Instance.PowerPointApp.SmartArtLayouts["MyLayOut"], 0f, 0f, width, height);

     Marshal.ReleaseComObject(smartartShape); smartartShape = null;

}



Public void UngroupSmartArt(PowerPoint.Shape shape)

{

     try

     {

            shape.Ungroup();

     }

     catch (Exception ex)

     {

            MessageBox.Show(ex.Message);

     }
}

Note: I am using VS Ultimate 2013, PowerPoint2013, C#


回答1:


In VBA, you'd do it like so, asssuming a reference to the smartart shape in osh:

osh.Copy
osh.Delete
Set osh = ActiveWindow.Selection.SlideRange(1).Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)
With osh.Ungroup
    .Ungroup
End With

Copy the SmartArt shape to the clipboard Delete it from the slide Paste it back onto the slide as an Enhanced Metafile Ungroup it then ungroup the result.

Voila. Shapes.

You'll want to pick up the top/left coordinates of the Smart Art before copying/deleting it, then apply them to the pasted EMF.




回答2:


Take a look at the Parent and ParentGroup properties of the Shape object. This might solve your problem.



来源:https://stackoverflow.com/questions/26977130/cannot-ungroup-a-powerpoint-smartart-shape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!