Home > Mobile >  How can I convert a graphic into a form by program as I can do it in PowerPoint UI from context menu
How can I convert a graphic into a form by program as I can do it in PowerPoint UI from context menu

Time:01-21

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?

CodePudding user response:

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 ...

CodePudding user response:

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
  • Related