Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA ungroup Shape (SmartArt)

Tags:

powerpoint

vba

Does anyone know how to ungroup SmartArt element via VBA?

Sub UngroupSmartArt()

Dim shapeWithSmartArt As Shape
Set shapeWithSmartArt = ActivePresentation.Slides(2).Shapes(2)

shapeWithSmartArt.Ungroup

End Sub

I get an error for this code: "This member can only be accessed for a group."

It doesn't make any sense to me, because it's easily possible to do it in powerpoint itself (Right click on SmartArt -> Group -> Ungroup). It's driving me nuts :)

Can anyone help me with ungrouping SmartArt element/shape?

I also took a look on similar question, but it doesn't work properly, because ungrouped result is different in comparison to the one made via powerpoint itself.

Please help me out. I would really appreciate any help!

like image 457
michael24B Avatar asked Oct 17 '22 16:10

michael24B


1 Answers

It is simply impossible to do it via VB code. That is also statement from Microsoft. Disadvantage of using SmartArt is also that user cannot record any actions with macro (using Excel) which are performed on this type of object/element.

It is also impossible to change width or height property of SmartArt nodes via VB, this was actually the reason why I wanted to change SmartArt element to shapes, because you can easily change width and height property of the shape via code.

Microsoft and their developers should really consider to make SmarArt element more developer-friendly, because I noticed I'm not the only one with these issues.

EDIT: Solution found! There is a way to execute commands from the powerpoint ribbon. You need to select your shape first, afterwards execute CommandBars.ExecuteMso with the action: SmartArtConvertToShapes.

Sub UngroupSmartArt()

Dim shapeWithSmartArt As Shape
Set shapeWithSmartArt = ActivePresentation.Slides(2).Shapes(2)

shapeWithSmartArt.Select
CommandBars.ExecuteMso("SmartArtConvertToShapes")

End Sub

This still doesn't change the fact and my point of view: Microsoft should really consider to make SmartArt element more friendly to developers!

like image 112
michael24B Avatar answered Oct 20 '22 18:10

michael24B