2017-04-18 141 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

謝謝!基於你的幫助和一些改變,我得到它的工作!剪輯是因爲圖片然後移動到最終位置。 –