Search code examples
vbaexcelpowerpoint

Insert hyperlink in a PowerPoint table cell with VBA


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

Solution

  • 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