Hover preview over excel image link
You made me curious, so I looked into this.
The answer is, yes - it requires a bit of VBA and is a bit hacky, but here's how you can do it.
First of all, doing anything on cell hover in excel is a bit hacky.
To do so, we use the HYPERLINK
formula of a cell.
=HYPERLINK(OnMouseOver("http://i.imgur.com/rQ5G8sZ.jpg"),"http://i.imgur.com/rQ5G8sZ.jpg")
In this case, I have the URL of a grumpycat picture in my formula.
I also pass this link to a function I create called OnMouseOver
Dim DoOnce As Boolean
Public Function OnMouseOver(URL As String)
If Not DoOnce Then
DoOnce = True
With ActiveSheet.Pictures.Insert(URL)
With .ShapeRange
.LockAspectRatio = msoTrue
.Width = 75
.Height = 100
End With
.Left = Cells(1, 2).Left
.Top = Cells(1, 2).Top
.Placement = 1
.PrintObject = True
End With
End If
End Function
Finally, in order to clear it when we hover away, we have to put some formulas in the other cells near it.
=HYPERLINK(Reset())
And the associated function:
Public Function Reset()
If DoOnce Then
DoOnce = False
ActiveSheet.Pictures.Delete
End If
End Function
Edit
Expanding on this with multiple links.
We can pass a cell reference along with this to do this with multiple links and have them appear next to the cell.
Dim DoOnce As Boolean
Public Function OnMouseOver(URL As String, TheCell As Range)
Reset
If Not DoOnce Then
DoOnce = True
With ActiveSheet.Pictures.Insert(URL)
With .ShapeRange
.LockAspectRatio = msoTrue
.Width = 300
.Height = 200
End With
.Left = Cells(TheCell.Row, TheCell.Column + 1).Left
.Top = Cells(TheCell.Row, TheCell.Column + 1).Top
.Placement = 1
.PrintObject = True
End With
End If
End Function
Public Function Reset()
If DoOnce Then
DoOnce = False
ActiveSheet.Pictures.Delete
End If
End Function
user1663590
Updated on July 30, 2022Comments
-
user1663590 almost 2 years
I wanted to know is it possible to preview image links by hovering mouse cursor over image urls in excel, or google sheets, or any spreadsheet editor.
-
Rubén about 7 yearsThe question doesn't follow the guidelines on How to Ask. I.E. it is too broad.
-
-
user1663590 about 7 yearslol I love that the cats. That was some clever coding thanks brother help me out alot
-
user1663590 about 7 yearsis there a way to quickly add formula to links when you have multiple links in a cell
-
user1274820 about 7 yearsI'd need to see your data to know what you're trying to do. Might be worth posting a new question
-
DannyhelMont almost 5 yearsreally nice VBA, but the multiple links edit one isn't working for me, while testing it out, I noticed that the "TheCell As Range" was the problem, couldn't fix that :/
-
user1274820 almost 5 yearsYou have to add a reference to the cell to your
HYPERLINK
code. Basically useHYPERLINK(OnMouseOver("http://url.to.image",A1),"Hyperlink Text")
whereA1
is the cell that you put the code in. -
DannyhelMont almost 5 years@user1274820 oh, it worked! thank you very much! as always I think about the messy possibilities before the simple ones, thought was something on VBA... -.-'. I didn't even thought that his script could accept references and the Excel yesterday wasn't even showing the #VALUE! error on the cells, only today... would have been a great opportunity to tip me about the error..., but well, my fault after all since its been a long time I didn't updated it. ¬¬' anyway, I really appreciated your help, thx. =)
-
StupidQuestionGuy almost 3 years@user1274820 great VBA! I have a question - I am attempting to do the second, multiple links version and I am getting a "Value" error. I tried the comment above - writing it as HYPERLINK(OnMouseOver("url.to.image",A1),"Hyperlink Text") - where A1 is a URL address of an image. I'm confused what I am supposed to put before the comma there - literally ""url.to.image", or something else?
-
user1274820 almost 3 years@StupidQuestionGuy you're supposed to put the link to an image. So if your image is at
http://i.imgur.com/rQ5G8sZ.jpg
you would put that. You can see what is in the cell at the top of the first gif in the post. It's a web address to the image.