use*_*590 5 excel vba google-sheets
我想知道是否可以通过将鼠标光标悬停在excel,google工作表或任何电子表格编辑器中的图像网址上来预览图像链接.
use*_*820 12
你让我好奇,所以我调查了这个.
答案是肯定的 - 它需要一点VBA并且有点hacky,但是这就是你可以做到的.
首先,在excel中进行单元格悬停的任何操作都有点笨拙.
为此,我们使用HYPERLINK单元格的公式.
=HYPERLINK(OnMouseOver("http://i.imgur.com/rQ5G8sZ.jpg"),"http://i.imgur.com/rQ5G8sZ.jpg")
在这种情况下,我的公式中有一张grumpycat图片的URL.
我也将此链接传递给我创建的函数调用 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
Run Code Online (Sandbox Code Playgroud)
最后,为了在我们徘徊时清除它,我们必须在它附近的其他单元格中放置一些公式.
=HYPERLINK(Reset())
以及相关的功能:
Public Function Reset()
If DoOnce Then
DoOnce = False
ActiveSheet.Pictures.Delete
End If
End Function
Run Code Online (Sandbox Code Playgroud)
编辑
通过多个链接扩展此功能.
我们可以传递一个单元格引用,以便使用多个链接执行此操作,并将它们显示在单元格旁边.
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
Run Code Online (Sandbox Code Playgroud)