excel - 向 SmartArt 节点添加超链接
问题描述
在 Excel(也包括 PowerPoint 和 Word)用户界面中,可以将超链接分配给 SmartArt 节点或节点中的文本:
在宏中记录这些步骤会产生一个空过程。
尝试对对象模型使用逻辑不会产生有用的结果(参见下面的代码)。我尝试了以下三种方法:
- A
SmartArtNode
有一个Shapes
属性,可以提取一个Shape
对象......但是该类型属于 Office 对象模型 (Office.Shape
) 并且不能被强制(我可以找到)到 aExcel.Shape
(也不是 aPowerPoint.Shape
)。试图将其分配给Excel.Shape
-Set xlShape = nd1.Shapes(1)
- 结果
运行时错误“13”类型不匹配
- 尝试在
Office.Shape
结果中添加超链接
运行时错误 -2147417848 (80010108)
自动化错误
调用的对象已与其客户端断开连接。
- 然后我尝试选择节点并将超链接添加到返回的
Application.Selection
(TypeName(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
解决方案
推荐阅读
- c# - 替换 C# 文件中的模式
- angularjs - 可以在 ui-router 延迟加载功能上添加控制器
- ios - 对于某些不支持 NFC 的设备,如何限制从 appstore 安装 ios 应用程序?
- javascript - 发出 AJAX 请求时如何修复“JSON 解析错误:意外的标识符数组”
- android - 如何使用计时器/处理程序更新数组适配器?
- python - 试图将真实和想象分开,但它会加起来
- java - 数组未正确更新,因为“显示数组”类对象在另一个类中初始化
- reactjs - Swiper - 将 .swiper-slide 宽度设置为小于 100% 时,轮播的最后 2 项中出现奇怪的视觉伪影
- python - 对 paramiko ssh 上的命令是否有可能回答是/否?
- powershell - 是否有任何命令可以切换设备的驱动程序?