vba powerpoint select a slide by name

后端 未结 2 1162
隐瞒了意图╮
隐瞒了意图╮ 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: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
    

提交回复
热议问题