Export selected shape as picture in VBA

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.

Answer
Answer

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.

Author of "OOXML Hacking - Unlocking Microsoft Office's Secrets", ebook now out
John Korchok, Production Manager
production@brandwares.com

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated December 24, 2023 Views 2,884 Applies to: