PDA

View Full Version : Saving each slide as jpg with the text in the slide as file name



hs1972
04-25-2018, 04:54 AM
I have a powerpoint file where I want to save each of the individual slides as jpgs. That bit is fine. The issue is I want the file names to be the text on the individual slide. So if a slide has the text 'Hello There' I want the slide to save as hello-there.jpg (all in lower case, up to 25 characters). Is there any way to do this? Is there any sample VBA script that anyone is aware of that does something similar so I'm not starting from scratch. I'm pretty new to this but willing to give it a go. Know a little VBA. Thanks in advance.

Paul_Hossler
04-25-2018, 06:55 AM
Where is the text on the slide located? i.e. in what/which 'container'?

A textbox? Which one? How to identify it?

A Placeholder? Which one?

A Shape? ...... etc.


What if the text contains non-file characters? e.g. \ or / or * etc?

Paul_Hossler
04-25-2018, 07:20 AM
If the 'text' in in the slide's title placeholder, then something like this

All depends on where the text is and how it can be identified




Option Explicit

Sub SaveEach()

Dim oPresentation As Presentation
Dim oSlide As Slide
Dim oShape As Shape
Dim sFilename As String

Set oPresentation = ActivePresentation

For Each oSlide In oPresentation.Slides
For Each oShape In oSlide.Shapes
With oShape
If .Type = msoPlaceholder Then
If .PlaceholderFormat.Type = ppPlaceholderCenterTitle Or _
.PlaceholderFormat.Type = ppPlaceholderTitle Then
If .HasTextFrame Then
If .TextFrame.HasText Then
sFilename = Left(LCase(.TextFrame.TextRange.Text), 25) & ".jpg"
On Error Resume Next
Kill sFilename
On Error GoTo 0
oSlide.Export sFilename, "jpg"
End If
End If
End If
End If
End With
Next
Next


End Sub