2

I am trying to select a slide by name. I have added a title via the outline. below is the code that is not working. "item Idaho not found in the slide collection"

ActivePresentation.Slides("Idaho").Select
user1813251
  • 329
  • 3
  • 18

2 Answers2

3

The slide's name and the text in the title placeholder nave nothing to do with one another.

Unless you've renamed it, the first slide in the presentation will be named "Slide1", the second "Slide2" and so on.

If you specifically need a way to locate the slide whose title text = "Idaho", you'd need to write a function to search all the slides in the presentation and return the first one it finds that meets your criteria. For example:

Sub TestMe()
    Dim oSl As Slide
    Set oSl = FindSlideByTitle("idaho")

    If Not oSl Is Nothing Then
        MsgBox "Found your title on slide " & CStr(oSl.SlideIndex)
    End If

End Sub
Function FindSlideByTitle(sTextToFind As String) As Slide
    Dim oSl As Slide

    For Each oSl In ActivePresentation.Slides
        With oSl.Shapes.Title.TextFrame
            If .HasText Then
                If UCase(.TextRange.Text) = UCase(sTextToFind) Then
                    Set FindSlideByTitle = oSl
                End If
            End If
        End With
    Next

End Function
Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34
  • thanks, that generally works, However, not all slides have titles. is there an easy way to check if a slide has a title before doing the textframe statement? – user1813251 Jul 30 '14 at 14:52
  • @user1813251 `ActivePresentation.Slides(1).Shapes.HasTitle` will return either True or False. – David Zemens Jul 30 '14 at 16:07
0

Reviving an old question, but I wanted to throw this in.

While it's possible that ActivePresentation.Slides("MySlideName").Select doesn't work, this does work for me in PPT 2010:

Dim PPTObj As PowerPoint.Application
Set PPTObj = New PowerPoint.Application
Dim PPTClinic As PowerPoint.Presentation
Set PPTClinic = PPTObj.Presentations.Open(FileName:="Your File Name Here")
PPTClinic.Slides("MySlideName").Select

This, of course, assumes that there is a slide named "MySlideName". Your code will have to deal with gracefully handling the Item MySlideName not found in the Slides collection. error (err.number = -2147188160).

FreeMan
  • 5,660
  • 1
  • 27
  • 53