vba powerpoint select a slide by name

后端 未结 2 1125
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 17:19

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\"



        
相关标签:
2条回答
  • 2021-01-21 17:42

    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).

    0 讨论(0)
  • 2021-01-21 17:45

    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
    
    0 讨论(0)
提交回复
热议问题