I have the following function that will display a picture if you run your mouse over it. It\'s quite neat and works well. However, I\'d like to change it from running your m
As "Double Click" enters into the editing of the excel cell, it may cause undesired edit of existing values/ formulas. So, I would recommend Worksheet_SelectionChange
event. You can use it with navigation/ arrow keys as well.
Paste the following code in VBA - relevant "Sheet" Object
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim url As String
On Error Resume Next 'to avoid error if the target cell does not have url
'Even if we can use URLExists function to avoid such error,
'there will still be errors when there is value but not recognised by the function.
'For example an error caused by function =100/0
ActiveSheet.Pictures.Delete
'If URLExists(Target.Value) Then
'As we are using "on error resume next statement we don't need this.
'here is a link to this function
'https://stackoverflow.com/a/25428811/9808063
url = Target.Value
With Me.Pictures.Insert(url)
With .ShapeRange
.LockAspectRatio = msoTrue
.Width = 300
.Height = 200
End With
.Left = Cells(Target.Row + 2, Target.Column + 1).Left
.Top = Cells(Target.Row + 2, Target.Column + 1).Top
.Placement = 1
.PrintObject = True
End With
'End If
End Sub
Answer to this question can be found at the link below.
https://www.mrexcel.com/board/threads/double-click-a-cell-to-show-a-picture-from-a-link.1136465/page-2