Share via

Adding hyperlinks to Text using vba

Anonymous
2015-02-23T08:08:22+00:00

Hi

How do I add hyperlinks to text in a slide in powerpoint 2010 using vba

Im currently using a summary slide and this prints to a slide using the text in the answer questions below

example of answer question - answer18 = "I dont know how to do this - refer to www.blah.co.uk" 'ADDED

 printableSlide.Shapes(2).TextFrame.TextRange.Text = _

        answer1 & vbCr & answer2 & vbCr & answer3 & vbCr & answer4 & vbCr & answer5 & vbCr & _

        answer6 & vbCr & answer7 & vbCr & answer8 & vbCr & answer9 & vbCr & answer10 & vbCr & answer11 & vbCr & answer12 & _

        vbCr & answer13 & vbCr & answer14 & vbCr & answer15 & vbCr & answer16 & vbCr & answer17 & vbCr & answer18

So how would I change the text in answer 18 " www.blah.co.uk" to a hyperlink is really what im asking

I need to use vba for this as the slide only gets addedd to the presentation at the end so I'm unable to add the hyperlinks direct to the slide in the normal way

thanks for any help you can give

Jinks

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

8 answers

Sort by: Most helpful
  1. Anonymous
    2015-02-23T08:55:38+00:00

    Your code is very hard to follow!

    To add a hyperlink you have to work with a TextRange.

    So:

    Take the TextRange in the shape, Find the part that is answer18 (which needs to be the link address without http:\) and add the action setting

    This should work but I can't see all of the code so some tweaking might be needed

    printableSlide.Shapes(2).TextFrame.TextRange.Text = _

            answer1 & vbCr & answer2 & vbCr & answer3 & vbCr & answer4 & vbCr & answer5 & vbCr & _

            answer6 & vbCr & answer7 & vbCr & answer8 & vbCr & answer9 & vbCr & answer10 & vbCr & answer11 & vbCr & answer12 & _

            vbCr & answer13 & vbCr & answer14 & vbCr & answer15 & vbCr & answer16 & vbCr & answer17 & vbCr & answer18

            With printableSlide.Shapes(2).TextFrame.TextRange.Find(answer18).ActionSettings(ppMouseClick)

            .Action = ppActionHyperlink

            .Hyperlink.Address = "http:\" & answer18

            End With

    Was this answer helpful?

    3 people found this answer helpful.
    0 comments No comments
  2. Steve Rindsberg 99,161 Reputation points MVP Volunteer Moderator
    2015-02-26T21:45:48+00:00

    Given a shape containing text and some text you want to apply a hyperlink to, here's a start:

    Function ReturnRange(oSh As Shape, sText As String) As TextRange

        Dim lStartChar As Long

        With oSh.TextFrame.TextRange

            lStartChar = InStr(.Text, sText)

            If lStartChar > 0 Then

                ' the text we want is there

                Set ReturnRange = .Characters(lStartChar, Len(sText))

                Exit Function

            End If

        End With

    End Function

    Sub TestMe()

        Dim oSh As Shape

        Dim oTxtRange As TextRange

        Set oSh = ActiveWindow.Selection.ShapeRange(1)

        Set oTxtRange = ReturnRange(oSh, "Click Here")

        If Not oTxtRange Is Nothing Then

            With oTxtRange

                MsgBox .Text

                .ActionSettings(ppMouseClick).Hyperlink.Address = "http://www.pptfaq.com"

            End With

        End If

    End Sub

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2015-02-23T15:16:01+00:00

    Try something like this

    Sub LinkLine18()

        printableSlide.Shapes(2).TextFrame.TextRange.Lines(18) _

            .ActionSettings(ppMouseClick).Hyperlink.Address = "http://www.blah.co.uk/"

    End Sub

    This works on the 18th line of the printable slide. Since you asked for the 18th answer, which should be the 18th line, it should work.

    --David

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2015-02-23T15:33:34+00:00

    Ah. Yes. Good thought. Paragraphs should work for this application. I believe his answers are in a placeholder but not a title placeholder. Thanks for the correction, John.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2015-02-23T15:25:39+00:00

    It will probably work as long as there are no multi line answers. Paragraphs( 18) might be better but it can still fail in the unlikely event the text is in a Title Placeholder.

    Was this answer helpful?

    0 comments No comments