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
Community
  • 1
  • 1
Sean
  • 15
  • 2
  • 6
  • Please clarify which object throws the error. If possible provide the full error information. – Paul Oct 21 '14 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... – Sean Oct 21 '14 at 18:58
  • For context, this is Excel VBA that is building a Powerpoint presentation. I have added the Powerpoint library reference. – Sean Oct 21 '14 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: http://www.msofficeforums.com/powerpoint/11271-vba-hyperlinks-table-cells.html – Paul Oct 21 '14 at 19:10
  • Yeah, I saw that code example... it's very similar to my current example. And it generates the same error. – Sean Oct 21 '14 at 19:49

2 Answers2

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

L42
  • 19,427
  • 11
  • 44
  • 68
  • 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." – Sean Oct 22 '14 at 16:03
  • I had to do this, instead: – Sean Oct 22 '14 at 16:05
  • '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 – Sean Oct 22 '14 at 16:06
  • 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. – Sean Oct 22 '14 at 16:07
  • Correction: the subaddress works. I neglected to put the space after the dot. – Sean Oct 22 '14 at 17:30
  • It looks like I'm good now, it works. The only mystery is why I'm forced to insert text and then hyperlink it versus just using the Hyperlink object from the TextRange. Thanks for your help, L42! – Sean Oct 22 '14 at 17:32
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.stack.imgur.com/gaMJK.png