VBA插入嵌入图片excel

时间:2013-06-14 14:06:44

标签: excel vba excel-vba access-vba

我看过很多关于我们xlApp.activesheet.Pictures.Insert(strImagePath)的帖子,用VBA将图片插入电子表格,效果很好。唯一的问题是它将其作为链接图片插入。因此,如果我将电子表格发送出网络,图像就会失败。任何人都可以告诉我如何使用Pictures.Insert将图像作为嵌入图像放置,或者可能是另一种将其嵌入的方法?如果有帮助的话,我也会从访问中调用此方法。

3 个答案:

答案 0 :(得分:20)

你可以使用shapes.addpicture方法

activesheet.Shapes.AddPicture Filename:="C:\test\desert.jpg", linktofile:=msoFalse, _
            savewithdocument:=msoCTrue, Left:=0, Top:=0, Width:=100, Height:=100

答案 1 :(得分:0)

请注意,您可以将所需的宽度和高度参数设置为-1,然后保持原始图像的高度和宽度!

Activesheet.Shapes.AddPicture Filename:="C:\image.jpg", LinkToFile:=msoFalse, _
        SaveWithDocument:=msoTrue, Left:=0, Top:=0, Width:=-1, Height:=-1

http://excelmatters.com/2013/11/25/default-picture-size-with-shapes-addpicture/

(作为另一个提高可见性的答案,因为我多年来一直在努力解决这个问题,并且没有在其他任何地方找到此解决方案。)

答案 2 :(得分:0)

Activesheet.Shapes.AddPicture Filename:="C:\image.jpg", LinkToFile:=msoFalse, _
        SaveWithDocument:=msoTrue, Left:=0, Top:=0, Width:=-1, Height:=-1

这可行,也许以下代码也可以帮助某人(它对我有帮助) 这是您选择刚刚添加的图像的方式:

ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Select