使用VBA在PowerPoint表格单元格中插入超链接
我正在使用PowerPoint 2007。我想使用列表在幻灯片上创建表格。每行的第一列都有一个指向演示文稿中不同幻灯片的超链接,就像摘要幻灯片一样 我在使用VBA将超链接插入单元格时遇到问题。错误消息通常类似于对象不支持该函数 下面是令人不快的一句话:使用VBA在PowerPoint表格单元格中插入超链接,vba,excel,powerpoint,Vba,Excel,Powerpoint,我正在使用PowerPoint 2007。我想使用列表在幻灯片上创建表格。每行的第一列都有一个指向演示文稿中不同幻灯片的超链接,就像摘要幻灯片一样 我在使用VBA将超链接插入单元格时遇到问题。错误消息通常类似于对象不支持该函数 下面是令人不快的一句话: With pptPres.Slides(2).Shapes("Table Summary").Table.Cell(i - 1, 1).Shape.ActionSettings(ppMouseClick).Hyperlink .TextT
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
你快到了。
如果要在表格或形状中的文本中添加链接,则需要访问。
比如:
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
而且,不能将SlideID属性用作子地址。
它应该是这样的格式:例如2。幻灯片2
为了实现这一点,我们使用了SlideNumber和Name属性。HTH谢谢您的上述介绍。下面为幻灯片2中的每张幻灯片生成一个超链接TOC表
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
请澄清哪个对象抛出错误。如果可能,请提供完整的错误信息。完整消息是运行时错误“445”:对象不支持此操作我非常确定是超链接对象导致了问题,因为没有其他原因导致错误。我似乎无法使用表外的.Cell.Shape…作为上下文,这是正在构建Powerpoint演示文稿的Excel VBA。我已经添加了Powerpoint库参考。因为我不是Powerpoint专家,所以我真的帮不了你。我发现了这条线索,虽然它可能会帮助你实现你想要实现的目标:是的,我看到了那个代码示例。。。这与我当前的示例非常相似。当我使用你的代码L42时,我仍然会得到一个错误。消息:运行时错误“2147188160 80048240”:超链接未知成员:请求无效。这类对象不能有与其关联的超链接。我必须这样做:使用pptTable.Celli-1,1.Shape.TextFrame.TextRange.Characters.ActionSettingsppMouseClick.hyperlink.Address=.SubAddress=pptPres.Slidesi.SlideNumber&.&pptPres.Slidesi.Name首先添加文本,然后进行超链接,这似乎是可行的。但是现在,我无法让子地址实际工作。甚至使用你上面建议的点符号。更正:子地址有效。我忘了在点后面加空格。