Reputation: 944
is there a way to add a hyperlink, provided from a cell, to an image?
I tried the following VBA code:
Sub Storage_Test_Click()
ActiveSheet.Hyperlinks.Add Anchor:=storage_image, Address:=Worksheets("Links").Range("B8:B8").Value
End Sub
But with this piece of code, the link is persistent. In other words, if I change the cell value, the link from the image is not affected.
Thanks, Tro
Upvotes: 0
Views: 6342
Reputation: 19727
Enter something like this in a Module
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
Then in your Link Sheet:
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
Is this what you're trying? HTH.
Upvotes: 1
Reputation: 1571
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Hyperlinks.Add Anchor:=storage_image, Address:=Worksheets("Links").Range("B8:B8").Value
End Sub
dont assign the macro to the image, because you can't click on the image (as it's a hyperlink!), if you right click your image with your original code after updating your link, im sure that selects it and your macro will run, however the above changes should mean everytime you make a selection on your sheet, your links will update
Upvotes: 0