Search code examples
vbapowerpoint

Automating the change in the Hyperlink of PowerPoint Shape in the Actions Menu


I have 50 shapes in Slide 1 named 1,2...50. I want them to hyperlink to the slide number of the shape name.

1: Select the shape go to Insert > Action > Hyperlink to > Slide... > Slide 1
5: Select the shape go to Insert > Action > Hyperlink to > Slide... > Slide 1

I can automate this by having a macro play on click of the shape

Sub GotoReqdSlide(oSh As Shape)
SlideShowWindows(1).View.GotoSlide Int(oSh.Name)
End Sub

However, I'm looking for a solution that would allow the hyperlinks to work even when macros are disabled. I tried automating the hyperlink process of Insert > Action > Hyperlink to > Slide... > Slide 1 using the following code but it didn't work out.

enter image description here

For i = 1 To 50
ActivePresentation.Slides(3).Shapes(i).ActionSettings(ppMouseClick).Hyperlink = "Slide " & i
Next i

I'd appreciate your help. Thank you!


Solution

  • Is this what you are trying?

    Dim pp As Presentation
    Set pp = ActivePresentation
    
    Dim i As Long
    
    For i = 1 To 50
        With pp.Slides(3).Shapes(i).ActionSettings(ppMouseClick)
            .Action = ppActionHyperlink
            .Hyperlink.SubAddress = pp.Slides(i).SlideNumber & _
                                    ". " & _
                                    pp.Slides(i).Name
        End With
    Next i