PowerPoint VBA - Picture Object, OLE Object file extension, type, or format

  • Thread starter Thread starter AD
  • Start date Start date
A

AD

I am writing an add-in that loops through a PowerPoint application and
exports all the included images. The problem is when I export the image
I need to specify a format (file type), however I can't find any way to
grab the format (file type) of the picture object or OLE object.

I hope I am just missing a reference; however I have looked endlessly
and can't find a solution.

Any help would be appreciated,

AD
 
AD,
No known native way to extract the format of the images stored within
PowerPoint. The hack is as follows:

Parse the HTML project for the slide. From which you can arrive at the
source property for the shape which will give you the filename and extension
of the original image.

This is a hack which works on 2000+ versions.
' ----- Beginning Of Code -----
Option Explicit


Function GetImageExtension(oCheckCopy As Object)
On Error GoTo ExitImageExtensionError
Dim oTmpPPT As Object
Dim sHTMLString As String
Dim sBuff As String


oCheckCopy.Copy
Set oTmpPPT = Presentations.Add(False)
With oTmpPPT.Slides.Add(1, ppLayoutBlank)
.Shapes.Paste
End With
sHTMLString = oTmpPPT.HTMLProject.HTMLProjectItems("Slide1").Text
If InStr(1, sHTMLString, "<v:imagedata src=" & Chr(34)) <> 0 Then
sBuff = Mid(sHTMLString, _
InStr(1, sHTMLString, "v:imagedata src=" & Chr(34)) _
+ Len("v:imagedata src=") + 1)
sBuff = Left(sBuff, InStr(1, sBuff, Chr(34)) - 1)
sBuff = Mid(sBuff, InStrRev(sBuff, ".") + 1)
End If
ExitImageExtensionError:
GetImageExtension = sBuff
oTmpPPT.Close
Set oTmpPPT = Nothing
End Function

Sub Test()
Dim sExt As String
Dim oShp As Shape
Set oShp = ActiveWindow.Selection.ShapeRange(1)
sExt = GetImageExtension(oShp)
MsgBox sExt
End Sub
' ----- End Of Code -----
 
I am writing an add-in that loops through a PowerPoint application and
exports all the included images. The problem is when I export the image
I need to specify a format (file type), however I can't find any way to
grab the format (file type) of the picture object or OLE object.

PowerPoint doesn't necessarily retain the original file type when you Insert a
picture from file. The image will be converted internally to GIF, JPG or PNG,
depending on the image characteristics (or if the image is JPG or PNG to begin
with, it'll stay that way).

IOW, if you're looking for TIFF In, TIFF Out, you can't get there from here.

If you save as web page from PPT 2000 or higher, you'll get the full resolution
image that PPT's holding internally (ie, after conversion to JPG/PNG/etc) among
all the other litter of support files.
 
Back
Top