Solved

Counting slides in powerpoint that meet a specified condition using vba

Posted on 2014-01-20
3
1,653 Views
Last Modified: 2014-01-27
I have a series of slides which I want to be able to count if they meet a specific condition (and perform other function on ideally). I tried doing this by

activepresentation.slides.shapes.title.name("test").count

but this doesn't work. I then tried to set this up as an array but I can't work out how to do that. I tried the following, but it's not working, as I think I can't define an array this way. I feel like this should be easy but I can't work it out.

Sub arraytest()

Dim ppt As Presentation
Dim s As Slide
Dim scurrent As Slide
Dim arraytest As Variant

Set ppt = ActivePresentation
Set s = ppt.Slides(ActiveWindow.Selection.SlideRange.SlideIndex)

arraytest = Array(ppt.Slides(ActiveWindow.Selection.SlideRange.SlideIndex))

For x = 1 To ppt.Slides.Count Step 1
    If ppt.Slides(x).Shapes.Title.Name = "test" Then
        ActiveWindow.View.GotoSlide (x)
        Set scurrent = ppt.Slides(ActiveWindow.Selection.SlideRange.SlideIndex)
    End If

    ReDim Preserve arraytest(UBound(arraytest) + 1)
    arraytest = ppt.Slides(ActiveWindow.Selection.SlideRange.SlideIndex)

Next

MsgBox ppt.Slides.Range(arraytest).Count

End Sub
0
Comment
Question by:jessicasimonk
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39794340
I think that you have several misconceptions.
This code creates an array of the slide indexes where the Title shape has text = "test"
Sub arraytest()

Dim ppt As Presentation
Dim s As Slide
Dim scurrent As Slide
Dim arraytest() As Integer
Dim x As Integer
Dim p As Integer

Set ppt = ActivePresentation

For x = 1 To ppt.Slides.Count Step 1
    If ppt.Slides(x).Shapes.Title.TextFrame.TextRange = "test" Then
        ReDim Preserve arraytest(p)
        arraytest(p) = x
        p = p + 1
   End If
Next x

MsgBox p & " slides found"

End Sub

Open in new window

0
 

Author Comment

by:jessicasimonk
ID: 39794555
Thank you - I knew I had it completely wrong but I'm a VBA newbie and couldn't work it out
0
 
LVL 23

Expert Comment

by:JSRWilson
ID: 39798480
Be careful not to have any slide with no title (eg blank) because it will crash.

Also it is probably easier without an array

Sub No_arraytest()
Dim osld As Slide
Dim raySlides() As Long
Dim iCount As Integer
Dim strReport As String
For Each osld In ActivePresentation.Slides
If osld.Shapes.HasTitle Then
If osld.Shapes.Title.TextFrame.TextRange = "test" Then
iCount = iCount + 1
strReport = strReport & "Slide " & osld.SlideIndex & ","
End If
End If
Next osld
Select Case iCount
Case Is > 1
MsgBox iCount & " Slides were found:" & vbCrLf & Left(strReport, Len(strReport) - 1)
Case 1
MsgBox iCount & " Slides was found:" & vbCrLf & Left(strReport, Len(strReport) - 1)
Case 0
MsgBox "None found."
End Select
End Sub
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
PowerPoint is the go-to presentation software for millions of users around the world. Many presentations use basic text features but you can really make special text jump out of your slide by applying this bubble text design process. This article ha…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This video teaches viewers how to add simple and professional themes to their slides.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question