【发布时间】:2017-05-11 18:29:12
【问题描述】:
我想知道是否可以通过将鼠标光标悬停在 excel、Google 表格或任何电子表格编辑器中的图片网址上来预览图片链接。
【问题讨论】:
-
该问题不符合How to Ask 上的指导方针。 IE。太宽泛了。
标签: excel vba google-sheets
我想知道是否可以通过将鼠标光标悬停在 excel、Google 表格或任何电子表格编辑器中的图片网址上来预览图片链接。
【问题讨论】:
标签: excel vba google-sheets
你让我好奇,所以我调查了这个。
答案是,是的 - 它需要一点 VBA 并且有点 hacky,但是您可以这样做。
首先,在 Excel 中对单元格悬停进行任何操作都有些 hacky。
为此,我们使用单元格的HYPERLINK 公式。
=HYPERLINK(OnMouseOver("http://i.imgur.com/rQ5G8sZ.jpg"),"http://i.imgur.com/rQ5G8sZ.jpg")
在这种情况下,我的公式中有一张暴躁猫图片的 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
最后,为了在我们悬停时清除它,我们必须在它附近的其他单元格中放置一些公式。
=HYPERLINK(Reset())
以及相关的功能:
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
【讨论】:
HYPERLINK 代码中。基本上使用HYPERLINK(OnMouseOver("http://url.to.image",A1),"Hyperlink Text") 其中A1 是您将代码放入的单元格。