2017-04-18 138 views
0

我有一个代码可以将数百张图片从网页链接添加到图片。它完美的工作!现在我需要修改它来为每张图片添加一个超链接,但我无法使其正常工作。任何帮助表示赞赏!超链接是包含图片的相同链接,在这个脚本中是变量Filename。这个想法是如果用户点击它,则以更大的尺寸打开图片。VBA添加指向图片的超链接

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

应该

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 
+0

谢谢!基于你的帮助和一些改变,我得到它的工作!剪辑是因为图片然后移动到最终位置。 –