2
votes

I have code that exports slides to PNG files if they meet certain criteria (i.e. have a certain named shape in the slide). There will be occassions where slides will not have any known shape names, but they will be within a named "section".

I know I must somehow use the ActivePresentation.SectionProperties, but I am not sure how to go about doing this. I've tried things along the line of the below code with no success. In this example the name of the section is "Test". There will be many different sections and I would need to do this for several of those sections. Any help would be much appreciated. Thank you!

Dim sld As Slide
i = 1

For Each sld in ActivePresentation.Slides

If ActivePresentation.SectionProperties.Name("Test") Then
   ActivePresentation.Slides(i).Export filenamepng & "TEST" & i & ".png", "PNG"
End If

i = i + 1

Next
1

1 Answers

4
votes

@Hunter21188

I guess this is what you need.

You will check of which section every slide belongs. After this you verify if it's from "Test" section, if is true gotcha! Export.

Obs. The function convert SectionIndex, from Slide Atribute to SectionName, that is not in Slides collection.

Sub Test_Export()

Dim sld As Slide
i = 1

DesiredSection = SectionIndexOf("Test")

For Each sld In ActivePresentation.Slides

If sld.sectionIndex = DesiredSection Then
   ActivePresentation.Slides(i).Export filenamepng & "TEST" & i & ".png", "PNG"
End If

i = i + 1

Next


End Sub

Function SectionIndexOf(sSectionName As String) As Long
    Dim x As Long
    With ActivePresentation.SectionProperties
        For x = 1 To .Count
            If .Name(x) = sSectionName Then
                SectionIndexOf = x
            End If
        Next
    End With
End Function