在Excel中通过单元格添加超链接到图像

有没有办法将一个单元格提供的超链接添加到图像?

我试了下面的VBA代码:

Sub Storage_Test_Click() ActiveSheet.Hyperlinks.Add Anchor:=storage_image, Address:=Worksheets("Links").Range("B8:B8").Value End Sub 

但是用这段代码,链接是持久的。 换句话说,如果我改变单元格的值,图像中的链接不受影响。

谢谢,Tro

Module中input这样的内容

 Sub Add_HLink(ws As Worksheet, picture_name As String) Dim sh As Worksheet: Set sh = Worksheets("Link") Dim shp As Shape For Each shp In ws.Shapes If shp.Type = msoPicture And shp.Name = picture_name Then ws.Hyperlinks.Add shp, sh.Range("B8").Value Exit For End If Next End Sub 

然后在你的链接表

 Private Sub Worksheet_Change(ByVal Target As Range) On Error GoTo halt Application.EnableEvents = False If Not Intersect(Target, [B8]) Is Nothing Then '~~> use the sub here, assuming Picture named "Picture 1" is in Sheet2 Add_HLink Sheet2, "Picture 1" '~~> change the arguments to suit End If continue: Application.EnableEvents = True Exit Sub halt: MsgBox Err.Description Resume continue End Sub 

这是你想要的吗? HTH。

 Private Sub Worksheet_SelectionChange(ByVal Target As Range) ActiveSheet.Hyperlinks.Add Anchor:=storage_image, Address:=Worksheets("Links").Range("B8:B8").Value End Sub 

不要指定macros的图像,因为你不能点击图像(因为它是一个超链接!),如果你右键点击你的图像与您的原始代码更新您的链接后,确保select它,你的macros将运行但是,上述更改应该意味着每次在表单上进行select时,链接都会更新