Export selected shape as picture in VBA

Anonymous
2020-05-06T14:23:19+00:00

Hi,

Pretty simple question, but I can't find an answer anywhere: how can I save the selected shape in PowerPoint as a picture using VBA?

What I want to get is an SVG to WMF file conversion macro. Now that PowerPoint has good SVG support, it does it pretty well manually. Here's what I have so far:

Sub svg2wmf()

svgFile = "path_to_svg_file"

'Insert the picture

ActiveWindow.Selection.SlideRange.Shapes.AddPicture( _

   FileName:=svgFile, _

   LinkToFile:=msoFalse, _

   SaveWithDocument:=msoTrue, _

   Left:=50, _

   Top:=50).Select

'Convert into shape (this is the only way I could find, maybe there's a better one now

Call CommandBars.ExecuteMso("SVGEdit")

'Now, how to I save the currently selected shape?

End Sub

In the end, I want to wrap it into a VBS script, but I'm still missing the last bit.

Thanks!

R.

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

John Korchok 234.7K Reputation points Volunteer Moderator
2020-05-06T14:58:07+00:00

Here's how to do that:

Sub ExportAsWMF()

    Call ActiveWindow.Selection.ShapeRange(1).Export("C:\filename.wmf", ppShapeFormatWMF)

End Sub

BTW, you might want to consider using EMF (ppShapeFormatEMF) instead of WMF, it's a more robust format that can handle more complex shapes than WMF.

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful