PDA

View Full Version : Exporting images in PowerPoint slides with filename from textbox



dcatt
08-26-2014, 07:02 AM
Hello,

I have about 20 PowerPoint files with 100 slides each; the slides contain a picture and a textbox that references the intended filename of the picture.

I want to write a VBA macro that will look at every slide and save the pictures to the PowerPoint filepath folder with a filename extracted from the text in the text box.

I've had trouble with the object export function as well as specifying the difference between the image and the text box. The code below doesn't even address trying to use the text contents of the textbox as a filename. Any help would be greatly appreciated.

David

Sub Picture()
Dim thePresentation As Presentation
Dim theSlides As Slides
Dim curSlide As Slide
Dim curShape As Shape
Dim CurrentPageName As String
Dim CurrentPageNumber As Integer
Dim CurrentFileIndex As Integer
Set thePresentation = ActivePresentation
Set theSlides = thePresentation.Slides
CurrentPageNumber = 0
For Each curSlide In theSlides 'get every single slide
CurrentPageNumber = CurrentPageNumber + 1
' go to each slide
For Each curShape In curSlide.Shapes ' inspect every shape
CurrentFileIndex = 1

If curShape.Type = 13 Then
fname = thePresentation.Path & "\" & "stuff\Page" & CurrentPageNumber & "_" & CurrentFileIndex & ".jpg"
curShape.Export fname, ppShapeFormatJPG
CurrentFileIndex = CurrentFileIndex + 1
End If
Next curShape
Next curSlide
End Sub

John Wilson
08-26-2014, 09:02 AM
You need to say which version you have and whether the images (and text) are in a placeholder or not.

dcatt
08-26-2014, 09:52 AM
I'm using PowerPoint 2010 and the images and text are displayed using the picture/caption slide format. The pictures are in picture placeholders, and the text that I want to extract as the filename is in the title placeholder directly beneath the picture.


12192

John Wilson
08-26-2014, 10:15 AM
Bear in mind I cant see your presentations and this may need some adapting!

See if it gets you close


Sub pic_exporter()
Dim osld As Slide
Dim oshp As Shape
Dim opic As Shape
Dim strTitle As String
Dim b_hasPic As Boolean
Dim iNum As Integer
For Each osld In ActivePresentation.Slides
strTitle = ""
b_hasPic = False
For Each oshp In osld.Shapes
If oshp.Type = msoPlaceholder Then
If oshp.PlaceholderFormat.ContainedType = msoPicture And oshp.PlaceholderFormat.Type = ppPlaceholderPicture Then
b_hasPic = True
Set opic = oshp
iNum = osld.SlideIndex
End If
If oshp.PlaceholderFormat.ContainedType = 1 And oshp.PlaceholderFormat.Type = ppPlaceholderTitle Then
If oshp.TextFrame.HasText Then strTitle = oshp.TextFrame.TextRange
End If
End If
Next oshp
If b_hasPic Then opic.Export ActivePresentation.Path & "\" & iNum & strTitle & ".jpg", ppShapeFormatJPG, _
ActivePresentation.PageSetup.SlideWidth * 2, ActivePresentation.PageSetup.SlideHeight * 2
Next osld
End Sub

dcatt
08-26-2014, 12:48 PM
Thanks. That worked great with very little adapting.