Share via

How do I add a hyperlink to the text or to a master slide that goes to a slide based on the ones I inserted?

Anonymous
2013-07-20T18:35:39+00:00

Hopefully last question. lol I need to add a hyperlink to the text or to a master slide that goes to a slide based on the ones I inserted. 

Example I insert 5 slides starting at slide 10 that goes to silde 15 then,

I insert 5 more slides at slide 30 and goes to slide 35.

My hyperlink for slide 10 goes to slide 30, 11 to 31, and so on... then on slide 30 to 10, 31 to 11, and so on.

Thanks!!

here is what I have so far:

Sub ExistingSlides()

Dim strTemp As String

Dim strPath As String

Dim strFileSpec As String

Dim oSld As Slide

Dim oLayout As CustomLayout

Dim oPic As Shape

Dim oTxt As Shape

' Edit these to suit:

strPath = "d:\My Pictures"

strFileSpec = "*.jpg"

strTemp = Dir(strPath & strFileSpec)

Do While strTemp <> ""

Set oLayout = ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1)

Set oSld = ActivePresentation.Slides.AddSlide(ActiveWindow.View.Slide.SlideIndex, oLayout)

Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _

LinkToFile:=msoFalse, _

SaveWithDocument:=msoTrue, _

Left:=0, _

Top:=0, _

Width:=100, _

Height:=100)

With oPic

' Set position:

.Left = 1.66 * 72

.Top = 0.85 * 72

' Set size:

.Height = 8.89 * 72

.Width = 14.53 * 72

End With

' Get the next file that meets the spec and go round again

strTemp = Dir

Loop

End Sub

[New question split by moderator from this answered question.

The moderator, who tried to get the essence of the question, supplied the title of the new question. The asker of the question may change the title by editing the question, and the moderator will not be offended in any way.

Note from moderator: new questions get answered much faster when asked as new questions. When a new question or follow-up question is tacked onto an answered question you can only hope a moderator stumbles across it and splits it off, which can take days, or may ever happen.]

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

6 answers

Sort by: Most helpful
  1. Anonymous
    2013-07-28T10:11:43+00:00

    It's pretty unclear what you need the hyperlink to do!

    Why are you setting the Width and Height of the added picture to 100? It makes no sense:

    A You already know the correct width and Height so you could just plug them in

    B I would never do this anyway unless you are certain you know the exact sizes.

    It's a common misconception that you must specify a height and width when adding pictures. You don't they are optional. If you just leave them out the picture will be inserted at its real size AND lockAspectratio will be set to True so that you only need adjust the height OR width to get the size needed with no distortion.

    Sub ExistingSlides()

    Dim strTemp As String

    Dim strPath As String

    Dim strFileSpec As String

    Dim oSld As Slide

    Dim oLayout As CustomLayout

    Dim oPic As Shape

    Dim oTxt As Shape

    ' Edit these to suit:

    strPath = "d:\My Pictures"

    strFileSpec = "*.jpg"

    strTemp = Dir(strPath & strFileSpec)

    Do While strTemp <> ""

    Set oLayout = ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1)

    Set oSld = ActivePresentation.Slides.AddSlide(ActiveWindow.View.Slide.SlideIndex, oLayout)

    Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _

    LinkToFile:=msoFalse, _

    SaveWithDocument:=msoTrue, _

    Left:=0, _

    Top:=0)

    With oPic

    ' Set position:

    .Left = 1.66 * 72

    .Top = 0.85 * 72

    ' Set size:

    .Height = 8.89 * 72 ' is this correct - it's very large!

    End With

    ' Get the next file that meets the spec and go round again

    strTemp = Dir

    Loop

    End Sub

    To add an internal hyperlink you need to add an action setting to the textrange for the link and give it an action of ppActionHyperlink and specify a subAddress to the correct slide.

    This example would create a link to slide 5. NOTE even if you later move the slide to a new position the link will still work.

    Sub createLink()

    Dim otxr As TextRange

    Dim osld As Slide

    Set osld = ActivePresentation.Slides(5)

    'assumes there is a slide 1 with the Title & Text layout!

    Set otxr = ActivePresentation.Slides(1).Shapes(2).TextFrame.TextRange.Paragraphs(1)

    otxr.Text = "Link to slide 5"

    With otxr.ActionSettings(ppMouseClick)

    .Action = ppActionHyperlink

    .Hyperlink.SubAddress = getSubAddress(osld) ' osld is slide 5

    End With

    End Sub

    Function getSubAddress(osld As Slide) As String

    Dim strID As String

    Dim strIndex As String

    Dim strTitle As String

    strID = osld.SlideID

    strIndex = osld.SlideIndex

    If osld.Shapes.HasTitle Then

    If osld.Shapes.Title.TextFrame.HasText Then

    strTitle = osld.Shapes.Title.TextFrame.TextRange

    Else

    strTitle = osld.Name

    End If

    End If

    getSubAddress = strID & "," & strIndex & "," & strTitle

    End Function

    Was this answer helpful?

    0 comments No comments
  2. Jim G 134K Reputation points MVP Volunteer Moderator
    2013-07-27T21:38:37+00:00

    OK - I'll move your question to a PowerPoint for Windows forum. If you reply with your OS version and PowerPoint version a moderator there can place your question appropriately.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2013-07-24T16:21:48+00:00

    This is for Windows.

    Was this answer helpful?

    0 comments No comments
  4. Jim G 134K Reputation points MVP Volunteer Moderator
    2013-07-24T16:13:29+00:00

    Are you doing this in PowerPoint for Windows or PowerPoint on a Mac? The file path example you have would work only on Windows.

    For assistance on using files and folders in VBA on a Mac, see this site.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2013-07-21T13:32:30+00:00

    Since no one has posted till now, let me bump it.

    That said you would get better help in the technet.

    Was this answer helpful?

    0 comments No comments