脱钩图片超链接

时间:2015-05-02 20:14:41

标签: excel vba excel-vba

我正在尝试使用vba从excel表中删除图片,但无法找到解决方案。

找到以下链接,但它适用于形状和图表,不适用于作为链接插入的图片: -

http://answers.microsoft.com/en-us/office/forum/office_2010-word/convert-linked-excel-charts-to-embedded-ones/357bb64d-b852-4e43-8671-b0f49f0dabc3

1 个答案:

答案 0 :(得分:0)

以下是4种可能有效的方法,没有一种是完美的,所以在调试模式下尝试

err.clear
on error resume next 'everything not working will throw an Error
with activesheet.shapes("Picture 1") 
    .type=13 'forcfully changing the type form a linketype to normal picture, might not work
    .linkformat.autoupdate = false 'might not work
    .hyperlink = false 'might not work
    .formula = VbNullString 'might not work

    'if all fails try the last hope (copy it but no link)
    .copy 'if fails : ActiveSheet.Pictures.Paste link:=True
    'activesheet.Pictures.Paste link:=True 'failed (works only for picture copy of ranges ?)
    ActiveSheet.PasteSpecial Format:="Picture (Enhanced Metafile)"
    'you can save .top and .left in a single variable and replace the new pic on the right place
    Dim X as single, Y as Single
    X=.left
    Y=.top


    with activesheet.shapes(activesheet.shapes.count) 'the new pic is the last in shapes collection
    'same result but i like it less, with : selection.shaperange.item(1) ' you need to be in the picture's sheet, wich in our case is ok because we work on activesheet
         .top=Y
         .left=X
         .name = "Picture 1"
     End with
     .delete 'removes the old picture
End With