Can I go to a specific PowerPoint slide using VBA?

I am trying to make a button on a slide that jumps to another slide called. I want to be able to do something like activeslide.view.slide ("Menu Slide")

This does not work, but I would have thought something like that ... Any help would be great!

+3
source share
2 answers

First you will need to actually name your slides. The slide property ".Name" is different from and is not associated with its name in your schema. I just say this because many people are not aware of this. You must set this property through VBA. If you do not, you may get unexpected results. PowerPoint will call the slide “Slide #” wherever it was inserted, so if you insert a slide in the middle of the presentation, you can have multiple slides with the same name. If you are looking for a specially named slide and have not renamed the slides, PowerPoint will return the first "slide" that it finds in any loop that you use to cycle through the slide collection. If you are editing a presentation and moving slides, this can give you a ton of problems. I would suggest renaming any slides,which, as you know, you will want to link later (or write something that will go through the entire collection of slides, and change the ".Name" property of each slide to its contents in the Title 1 object).

Sub ChangeSlideName()

    Dim NewName As String
    Dim ActiveSlide As Slide

    Set ActiveSlide = ActiveWindow.View.Slide

    NewName = InputBox("Enter new slide name for slide " & _
              ActiveSlide.SlideIndex, "New Slide Name", ActiveSlide.Name)

    If NewName = "" Then

        Exit Sub

    End If

    ActiveSlide.Name = NewName

End Sub


, . , , .

Function GetSlideIndex(SlideName As String)

    For Each Slide In ActivePresentation.Slides

        If Slide.Name = SlideName Then

            GetSlideIndex = Slide.SlideIndex
            Exit Function

        End If

    Next

End Function


, .

Sub MoveToSlide()

    SlideShowWindows(1).View.GotoSlide GetSlideIndex("YourSlideName")

End Sub

: MoveToSlide Click Mouse Over Actions , . , , " → → " " ".

+5

Function GetSlideIndex(Slide As String) As Integer
    Dim retVal As Integer
    retVal = 0
    For i = 1 To ActivePresentation.Slides.Count
        If ActivePresentation.Slides(i).Name = Slide Then
            retVal = i
            Exit For
        End If
    Next
    GetSlideIndex = retVal
End Function

CommandButton

Private Sub CommandButton1_Click()
    SlideShowWindows(1).View.GotoSlide GetSlideIndex("Slide2"), 1
End Sub
+4

Source: https://habr.com/ru/post/1788235/


All Articles