How do I extract all the images from a PowerPoint file programatically using COM?
A:
Well, there are two ways. One of them is for PowerPoint 2007 and 2010 only. But:
- It's not COM - you just open the file as a zip and go to the /media folder and then you have access to all the images.
- These are the raw images, not the images that PowerPoint renders if you've apply any affects to them (like Brightness/Contrast, Recolor, etc.).
The way in COM is through a depreciated feature called Shape.Export. In order to get access to it's Intellisense, you have to choose "Show Hidden Members" in the VBE (assuming you're using VBA for this). Here's the code for using it:
Sub SaveAllPictures()
Dim ap As Presentation: Set ap = ActivePresentation
Dim savePath As String
savePath = "C:\Users\me\Desktop\files\"
Dim i As Integer
Dim sl As Slide
Dim sh As Shape
For Each sl In ap.Slides
For Each sh In sl.Shapes
If sh.Type = msoPicture Then
sh.Export PathName:=savePath & sh.Name & CStr(i) & ".png", Filter:=ppShapeFormatPNG
i = i + 1
End If
Next
Next
End Sub
Otaku
2010-07-07 02:39:54