抓取Excel超链接&插入PowerPoint表格

时间:2015-11-06 21:15:38

标签: excel vba hyperlink powerpoint

我正在跟进两个问题(Here& Here),这些问题是关于使用VBA从Excel获取超链接并将其插入PowerPoint的问题。

下面是我的代码 - 我尝试用它进行调整,但我无法将超链接放入单元格并显示文本,因为它永远不会超过这一点:

.Address = getAddress

代码中断了以下错误消息:“运行时错误'438':对象不支持此属性或方法。”

如果这是重演,我道歉。任何帮助将不胜感激。

Option Explicit
Sub PPTableMacro()

    Dim oPPTApp As PowerPoint.Application
    Dim oPPTShape As PowerPoint.Shape
    Dim oPPTFile As PowerPoint.Presentation
    Dim SlideNum As Integer  
    Dim strPresPath As String
    Dim strExcelFilePath As String
    Dim getAddress As Hyperlink

    strPresPath = "C:\Somewhere...\Presentation.pptm"

    Set oPPTApp = CreateObject("PowerPoint.Application")
    oPPTApp.Visible = msoTrue

    Set oPPTFile = oPPTApp.Presentations.Open(strPresPath)
    SlideNum = 4
    oPPTFile.Slides(SlideNum).Select

    Set oPPTShape = oPPTFile.Slides(SlideNum).Shapes("Table 1")

    Sheets("Sheet1").Activate

    Set getAddress = Sheet1.Range("F1").Hyperlinks(1)

    oPPTShape.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = Cells(1, 1)
    oPPTShape.Table.Cell(2, 2).Shape.TextFrame.TextRange.Text = Cells(1, 2)
    oPPTShape.Table.Cell(3, 2).Shape.TextFrame.TextRange.Text = Cells(1, 3)
    oPPTShape.Table.Cell(4, 2).Shape.TextFrame.TextRange.Text = Cells(1, 4)
    oPPTShape.Table.Cell(5, 2).Shape.TextFrame.TextRange.Text = Cells(1, 5)
    With oPPTShape.Table.Cell(6, 2).Shape.TextFrame.TextRange.ActionSettings(ppMouseClick).Hyperlink
        .Address = getAddress.Address
        .TextToDisplay = "Link"
    End With

    Set oPPTShape = Nothing
    Set oPPTFile = Nothing
    Set oPPTApp = Nothing

End Sub

编辑:所以我一直在网上搜索遇到这个问题的其他人,但到目前为止我还没有运气。在我可以找到帮助的堆栈溢出上没有其他任何东西,我也没有在Office 2010的Microsoft开发人员站点上找到任何内容。我查看了那里提供的Hyperlink.TextToDisplay ="..."属性的示例,看起来我正在做所有事情对。我希望编辑我的问题不是一个便宜的镜头,希望有人会看到它,但我不知道还有什么可以做这个。

0 个答案:

没有答案