Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hover preview over excel image link

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.

like image 953
user1663590 Avatar asked May 11 '17 18:05

user1663590


People also ask

How do you use mouseover in Excel?

In Excel, you can create a picture that will appear when you position the mouse over a cell by inserting a note. First, insert a note. Right-click the cell where you want to show a mouseover picture (in this example, B2) and choose New Note.

How do I create a hyper link image in Excel?

The steps to make a picture or cell of Excel clickable are listed as follows: Select the picture or the cell containing the text which needs to be made clickable. Right-click the selection and choose “hyperlink” from the context menu. The selection and “hyperlink” option are shown in the following image.


1 Answers

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

Results: Results

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

Results2

like image 73
user1274820 Avatar answered Sep 20 '22 23:09

user1274820