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

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
 
S

Shyam Pillai

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top