0

In the PowerPoint UI I can convert a graphic into AutoShapes using the Group>Ungroup command in the context menu. It is converted into a group of shapes. Additionally it is possible to regroup them. Why are these methods either missing (in case of conversion) or raising errors (in case of ungrouping) for msoShapeType = 28?

John Korchok
  • 4,723
  • 2
  • 11
  • 20
Kalle
  • 149
  • 5
  • File format of the graphic in question? Listing of code used? Text of error messages along with which lines raise them? – John Korchok Jan 18 '23 at 18:15
  • If you are planning to ungroup imported vector images with VBA into shapes, it seems it is not possible. There is already a question about it, https://stackoverflow.com/q/64276775/18247317, which is unanswered. However, I am just guessing since your question is not clear. – Oran G. Utan Jan 18 '23 at 20:42
  • msoShapeType = 28 suggests that it's an inserted icon. I see that when you try to ungroup one of these, the error message complains that it's not a group. True. But you CAN ungroup e.g. imported EMF graphics, though they're not a group either. A bug in the OM perhaps, but that also suggests a workaround. Copy the icon, paste as EMF and ungroup that instead. – Steve Rindsberg Jan 18 '23 at 21:05
  • Sounds like a good idea. Detours with copy/paste already helped often in the past. I tried already some workarounds with copy/paste but not this one. Unfortunately, also for these shape types vba is complaining that it not is a group. – Kalle Jan 20 '23 at 08:07

2 Answers2

2

Here's an example that works here. Note that some of the shapes in ungrouped SVGs can be edited using Edit Points but the EMF version cannot. I don't know why that'd be. A limitation of EMF, perhaps.

Sub TestConvert()
' Ungroups the currently selected icon shape

Dim oSh As Shape
Dim oSl As Slide

Set oSh = ActiveWindow.Selection.ShapeRange(1)
Set oSl = oSh.Parent

' Copy the shape then paste it back as an EMF
oSh.Copy
ActiveWindow.View.PasteSpecial ppPasteEnhancedMetafile
' At this point you might want to oSh.Delete to remove the original shape

' get a reference to the newly pasted EMF
Set oSh = oSl.Shapes(oSl.Shapes.Count)
' Ungroup it
Set oSh = oSh.Ungroup(1)
' Ungroup it again
oSh.Ungroup

End Sub
Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34
  • Thank you. This is working for me now. I tried s.th. similar already after your first hint. But I assume I must have gotten the wrong shape to ungroup. – Kalle Jan 23 '23 at 08:32
1

Maybe I need to dig a little further: The original use case was to export a graphic shape originally inserted from svg file back again into an svg file. We were facing two problems:

  • Exporting a powerpoint shape to an svg file from the UI creates a vector graphic wrapper for a pixel graphic even if the shape was originally inserted from an svg file. If you insert the new svg file again into powerpoint it is still recognized as graphic but it does not behave as before. The vector benefits are lost. For example you cannot colour its frames.
  • No svg option was given to the almost not documented vba shape.export method.

For the first problem we found the workaround to "Convert To Shape" first. Exporting the group of shapes creates a proper svg file, which after inserting again into powperpoint behaves like the originally inserted svg file. For the second problem we tried some third party libraries, but all exported the shape into a similar vector graphic wrapper for a pixel graphic as Powerpoint UI did before and working fine with prior converted group of shapes.

So the idea was to combine both workarounds and convert the graphic into a group of shapes and exporting it into an svg file with help of a third party library. But converting a graphic (type=28) unfortunately cannot be converted by vba (see above).

Exporting to emf does not make a difference. It creates a vector graphic wrapper for a pixel graphic inside. The advantage of the svg file was that you can open it with a text editor and have a look what is inside.

Maybe someone has an idea, how to solve the original use case with a completely different approach. Thank you for reading ...

Kalle
  • 149
  • 5