通过Excel图像链接hover预览
我想知道是否有可能通过将鼠标光标hover在Excel中的图像URL或Google表格或任何电子表格编辑器上来预览图像链接。
你让我好奇,所以我看着这个。
答案是,是的 – 它需要一点VBA,有点不好意思,但是你可以这样做。
首先,在excel中做任何关于单元格hover的事情都是有点怪异的。
为此,我们使用单元的HYPERLINK
公式。
=HYPERLINK(OnMouseOver("http://i.imgur.com/rQ5G8sZ.jpg"),"http://i.imgur.com/rQ5G8sZ.jpg")
在这种情况下,我的公式中有一个grumpycat图片的URL。
我也通过这个链接到我创build的函数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
最后,为了在我们hover的时候清除它,我们必须在靠近它的其他单元中放置一些公式。
=HYPERLINK(Reset())
和相关的function:
Public Function Reset() If DoOnce Then DoOnce = False ActiveSheet.Pictures.Delete End If End Function
结果:
编辑
通过多个链接进行扩展。
我们可以传递一个单元格引用,并使用多个链接来执行此操作,并将它们显示在单元格的旁边。
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