首页 > 解决方案 > 向 SmartArt 节点添加超链接

问题描述

在 Excel(也包括 PowerPoint 和 Word)用户界面中,可以将超链接分配给 SmartArt 节点或节点中的文本:

在 UI 中添加 SmartArt 的超链接

在宏中记录这些步骤会产生一个空过程。

尝试对对象模型使用逻辑不会产生有用的结果(参见下面的代码)。我尝试了以下三种方法:

  1. ASmartArtNode有一个Shapes属性,可以提取一个Shape对象......但是该类型属于 Office 对象模型 ( Office.Shape) 并且不能被强制(我可以找到)到 a Excel.Shape(也不是 a PowerPoint.Shape)。试图将其分配给Excel.Shape- Set xlShape = nd1.Shapes(1)- 结果

运行时错误“13”类型不匹配

  1. 尝试在Office.Shape结果中添加超链接

运行时错误 -2147417848 (80010108)

自动化错误
调用的对象已与其客户端断开连接。

  1. 然后我尝试选择节点并将超链接添加到返回的Application.SelectionTypeName(Application.Selection)返回Shape

运行时错误 1004
应用程序定义或对象定义错误

如何将超链接添加到 SmartArt 节点?

Sub AddHyperlinkToSmartArtNode()
  Dim sa As SmartArt
  Dim ws As Worksheet
  Dim nd1 As SmartArtNode
  Dim shp As Office.Shape
  Dim shpx
  Dim rng As TextRange2

  Set ws = ActiveSheet
  Set sa = ws.Shapes(1).SmartArt
  Set nd1 = sa.Nodes(1)

  'Dim xlShape As Excel.Shape
  'Set xlShape = nd1.Shapes(1)
  'Run-time error '13'
  'Type mismatch

  Set shp = nd1.Shapes(1)

  'ws.Hyperlinks.Add shp, "www.google.com"
  'Run-time error -2147417848 (80010108)
  'Automation error
  'The object invoked has disconnected from its clients.

  Set rng = shp.TextFrame2.TextRange
  rng.Select
  Set shpx = Application.Selection
  ws.Hyperlinks.Add shpx, "www.google.com"
  'Run-time error 1004
  'Application-defined or object-defined error
End Sub

标签: excelvbapowerpoint

解决方案


推荐阅读