VBA插入嵌入式图片excel

时间:2021-01-02 02:29:12

I have seen lots of posts about us xlApp.activesheet.Pictures.Insert(strImagePath) to insert pictures into a spreadsheet with VBA, which works great. The only problem is it inserts it as a linked picture. So if I send the spreadsheet out of our network the images fail. Can anyone tell me how to use Pictures.Insert to place the image as an embedded image, or maybe another method that will place it embedded? I am also calling this method from access if that helps at all.

我看到过很多关于us xlApp.activesheet.Pictures.Insert(strImagePath)的文章,它可以用VBA将图片插入电子表格,效果非常好。唯一的问题是它将它作为一个链接图片插入。如果我把电子表格从网络中发送出去图像就会失败。谁能告诉我怎么用图片。插入以将图像作为嵌入的图像放置,或者使用其他方法将其嵌入?如果有帮助的话,我也会从access调用这个方法。

2 个解决方案

#1


18  

you can use the shapes.addpicture method

你可以使用这些形状。addpicture方法

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

#2


0  

Note that you can set the required Width and Height parameters to -1, which then maintains the height and width of the original image!

注意,您可以将所需的宽度和高度参数设置为-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/

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

(Added as another answer to increase visibility as I've struggled with this problem for ages and haven't found this solution documented anywhere else.)

(增加了另一个增加可见性的答案,因为我已经在这个问题上挣扎了很长时间,在其他地方也找不到这个解决方案。)

#1


18  

you can use the shapes.addpicture method

你可以使用这些形状。addpicture方法

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

#2


0  

Note that you can set the required Width and Height parameters to -1, which then maintains the height and width of the original image!

注意,您可以将所需的宽度和高度参数设置为-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/

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

(Added as another answer to increase visibility as I've struggled with this problem for ages and haven't found this solution documented anywhere else.)

(增加了另一个增加可见性的答案,因为我已经在这个问题上挣扎了很长时间,在其他地方也找不到这个解决方案。)