我有一个代码可以将数百张图片从网页链接添加到工作表中。它完美无缺!现在我需要修改它以添加每个图片的超链接,我无法让它工作。任何帮助表示赞赏!超链接是包含图片的链接,在此脚本中是变量Filename。我们的想法是,如果用户点击图片,则以更大的尺寸打开图片。
Line_dest = n - 1
Filename = Sheets("LISTOFLINKS").Cells(n, 15).Value
Rows(Line_dest).RowHeight = 100
ActiveSheet.Pictures.Insert(Filename).Select
Set shp = Selection.ShapeRange.Item(1)
With shp
.LockAspectRatio = msoTrue
.Width = 180
If .Height > 95 Then .Height = 95
.Cut
End With
Selection.Hyperlinks.Add
Anchor:=Selection.ShapeRange.Item(1), _
Address:=Filename
谢谢
答案 0 :(得分:0)
应该是
ActiveSheet.Hyperlinks.Add _
Anchor:=shp, _
Address:=Filename
您应该删除.Cut
。这会切割图像(如 ctrl + x ),如果删除,则无法添加链接。或者,您可以在剪切之前添加超链接:
ActiveSheet.Pictures.Insert(Filename).Select
Set shp = Selection.ShapeRange.Item(1)
ActiveSheet.Hyperlinks.Add Anchor:=shp, Address:=Filename
With shp
.LockAspectRatio = msoTrue
.Width = 180
If .Height > 95 Then .Height = 95
'.Cut 'removed that I guess you don't want the image to be cut
End With