Vba 断开图片超链接
我正在尝试使用vba从excel工作表中断开图片链接,但找不到解决方案 可在下面的链接中找到,但它适用于形状和图表,不适用于作为链接插入的图片:-Vba 断开图片超链接,vba,excel,Vba,Excel,我正在尝试使用vba从excel工作表中断开图片链接,但找不到解决方案 可在下面的链接中找到,但它适用于形状和图表,不适用于作为链接插入的图片:- 图像仍然是一个形状。共享您的代码,因为您可能缺少一个错误如果是带有超链接的简单图像,请尝试以下操作 ActiveSheet.Shapes.Range(Array("Picture 1")).ShapeRange.Item(1).Hyperlink.Delete 否则执行以下操作-转到“开发人员”选项卡并单击“录制宏”。接下来,从图像中手动删除超链接
图像仍然是一个形状。共享您的代码,因为您可能缺少一个错误如果是带有超链接的简单图像,请尝试以下操作
ActiveSheet.Shapes.Range(Array("Picture 1")).ShapeRange.Item(1).Hyperlink.Delete
否则执行以下操作-转到“开发人员”选项卡并单击“录制宏”。接下来,从图像中手动删除超链接,然后再次点击以停止录制宏。然后转到VBA项目,查看删除超链接的结果代码。这里有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
我尝试了ActiveDocument.Shapes.Item(1).Hyperlink.Delete,但无效。我也无法找到一种方法来手动断开图像的链接。图像已链接,并且图像不包含超链接,因此当我转到超链接时,我找不到文件位置。请检查形状的名称,然后用名称尝试我的代码。如果可能,请共享您的工作簿我正在添加链接,它包含vba内容附件中的图像由我在上面介绍的宏(ActiveSheet.Shapes.Range(数组(“图片1”))正确引用,但是,没有附加到它们的超链接-因此,没有要删除的内容,正如我在评论中所说,图像被添加为“文件链接”,并且图像不包含超链接。这就是图像被破坏的原因。