Excel 将超链接添加到SmartArt节点
在Excel(以及PowerPoint和Word)用户界面中,可以将超链接指定给SmartArt节点或节点中的文本: 在宏中记录这些步骤将生成一个空过程 尝试对对象模型使用逻辑不会产生任何有用的结果(请参见下面的代码)。我尝试了以下三种方法:Excel 将超链接添加到SmartArt节点,excel,vba,powerpoint,Excel,Vba,Powerpoint,在Excel(以及PowerPoint和Word)用户界面中,可以将超链接指定给SmartArt节点或节点中的文本: 在宏中记录这些步骤将生成一个空过程 尝试对对象模型使用逻辑不会产生任何有用的结果(请参见下面的代码)。我尝试了以下三种方法: SmartArtNode具有Shapes属性,可以提取Shape对象。。。但该类型属于Office对象模型(Office.Shape),无法强制(我可以找到)为Excel.Shape(也不能强制为PowerPoint.Shape)。尝试将其分配给一个Ex
SmartArtNode
具有Shapes
属性,可以提取Shape
对象。。。但该类型属于Office对象模型(Office.Shape
),无法强制(我可以找到)为Excel.Shape
(也不能强制为PowerPoint.Shape
)。尝试将其分配给一个Excel.Shape
-Set xlShape=nd1.Shapes(1)
-会导致办公室。形状
会导致调用的对象已与其客户端断开连接
Application.Selection
(TypeName(Application.Selection)
返回Shape
),返回应用程序定义或对象定义错误 如何将超链接添加到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
在我看来,它像一个Excel对象模型缺陷。我能够在Word中记录这一点,它成功地运行:ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range,Address:=“”,SubAddress:=“”,但Excel中的类似行仅返回运行时错误“438”:对象不支持此属性或方法。