Insert hyperlink in a PowerPoint table cell with VBA

戏子无情 提交于 2019-12-08 10:42:22

问题


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

回答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



来源:https://stackoverflow.com/questions/26493140/insert-hyperlink-in-a-powerpoint-table-cell-with-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!