0

I'm working with PowerPoint 2007. I want to use a list to create a table on a slide. The first column of each row will have a hyperlink to a different slide in the presentation (like a summary slide).

I'm having trouble using VBA to insert a hyperlink into a cell. The error message is usually something like "object doesn't support that function".

Here is the offending line:

With pptPres.Slides(2).Shapes("Table Summary").Table.Cell(i - 1, 1).Shape.ActionSettings(ppMouseClick).Hyperlink
    .TextToDisplay = ThisWorkbook.Sheets(i).Range("B1")
    .SubAddress = pptPres.Slides(i).SlideID
End With
5
  • Please clarify which object throws the error. If possible provide the full error information. Commented Oct 21, 2014 at 18:05
  • Full message is "Run-time error '445': Object doesn't support this action" I'm pretty sure that the Hyperlink object is causing the problem, since nothing else causes the error. I just can't seem to using that off of Table.Cell.Shape... Commented Oct 21, 2014 at 18:58
  • For context, this is Excel VBA that is building a Powerpoint presentation. I have added the Powerpoint library reference. Commented Oct 21, 2014 at 19:02
  • Since i am not a Powerpoint guru i can not really help. I found this thread though that might help you do what you are trying to achive: msofficeforums.com/powerpoint/… Commented Oct 21, 2014 at 19:10
  • Yeah, I saw that code example... it's very similar to my current example. And it generates the same error. Commented Oct 21, 2014 at 19:49

2 Answers 2

1

You're almost there.
You need to access TextRange Object if you want to add a Link in the text within a table or shape.
Something like:

Sub marine()
    Dim t As Table
    Dim pptpres As Presentation

    Set pptpres = ActivePresentation
    Set t = pptpres.Slides(1).Shapes(1).Table

    With t.Cell(2, 1).Shape.TextFrame.TextRange.ActionSettings(ppMouseClick).Hyperlink
        .TextToDisplay = "Link to Slide"
        .SubAddress = pptpres.Slides(2).SlideNumber _
            & ". " & pptpres.Slides(2).Name
    End With
End Sub

And also, you cannot use SlideID property as SubAddress.
It should be in this format: <slide number><dot><space><slide name> (eg. #2. Slide2)
To get this done we used SlideNumber and Name property instead. HTH

Sign up to request clarification or add additional context in comments.

6 Comments

I still get an error when I use your code, L42. Msg: "Run-time error '2147188160 (80048240)': Hyperlink (unknown member): Invalid request. This kind of object cannot have a hyperlink associated with it."
I had to do this, instead:
'code' With pptTable.Cell(i - 1, 1).Shape.TextFrame.TextRange.Characters().ActionSettings(ppMouseClick).Hyperlink .Address = "" .SubAddress = pptPres.Slides(i).SlideNumber & "." & pptPres.Slides(i).Name End With
Adding the text first, and then hyperlinking it seems to work. Now, though, I can't get the subaddress to actually work. Even using the dot notation you suggest above.
Correction: the subaddress works. I neglected to put the space after the dot.
|
0

thanks for the above. Below generates a hyperlinked TOC table for each slide into slide 2

Sub DeckTOC()                                                                      ' Creates a hyperlinked TOC of each slide in deck
' Tip: add a return-to-TOC hyperlink on Slidemaster default layout
' assumes slide 1 is a cover slide, slides 2 is for TOC
' and #2 already includes a table And (important) no other shapes or title
' with col 1 for slide title  and 2nd cloumn for slide no

' TOC can be formatted before/after macro has run
    Dim slidecount As Integer
    Dim t As Table
    Dim TOCrow As Integer
    Dim pptpres As Presentation
    
    Set pptpres = ActivePresentation
    slidecount = pptpres.Slides.Count
    If slidecount < 3 Then Exit Sub                                                ' nothing to do

    Set t = pptpres.Slides(2).Shapes(1).Table                                  ' grab= ther toc

    TOCrow = 2
    For i = 3 To slidecount Step 1                                                  ' get slide references for each slide
        If TOCrow > t.Rows.Count Then t.Rows.Add                         ' add rows on fly as needed

        ' create text entry in cell, then add hyperlink (doing in one step fails)

        With t.Cell(TOCrow, 1).Shape.TextFrame.TextRange
                .Text = pptpres.Slides(i).Shapes.Title.TextFrame.TextRange.Characters
        End With
        With t.Cell(TOCrow, 1).Shape.TextFrame.TextRange.Characters().ActionSettings(ppMouseClick).Hyperlink
                .Address = ""
                .SubAddress = pptpres.Slides(i).SlideNumber & ". " & pptpres.Slides(i).Name
        End With
        t.Cell(TOCrow, 2).Shape.TextFrame.TextRange.Text = i
    TOCrow = TOCrow + 1
    Next

End Sub


ex [enter image description here][1]


  [1]: https://i.sstatic.net/gaMJK.png

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.