vba 如何插入嵌入的图片?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17110425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to insert an embedded picture?
提问by DasPete
xlApp.activesheet.Pictures.Insert(strImagePath)
inserts pictures into a spreadsheet as a linked picture. If I send the spreadsheet out of our network the images fail.
xlApp.activesheet.Pictures.Insert(strImagePath)
将图片作为链接图片插入到电子表格中。如果我将电子表格从我们的网络中发送出去,图像就会失败。
How can I place an image as an embedded image?
如何将图像作为嵌入图像放置?
I am also calling this method from Access.
我也在 Access 中调用此方法。
回答by JosieP
you can use the shapes.addpicture method
您可以使用 shape.addpicture 方法
activesheet.Shapes.AddPicture Filename:="C:\test\desert.jpg", linktofile:=msoFalse, _
savewithdocument:=msoCTrue, Left:=0, Top:=0, Width:=100, Height:=100
回答by Michael
Note that you can set the required Width and Height parameters to -1, which then maintains the height and width of the original image!
注意可以将需要的Width和Height参数设置为-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.)
(添加为另一个答案以提高可见性,因为我多年来一直在努力解决这个问题,并且在其他任何地方都没有找到此解决方案的记录。)
回答by AG9
Activesheet.Shapes.AddPicture Filename:="C:\image.jpg", LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, Left:=0, Top:=0, Width:=-1, Height:=-1
this works, maybe the following code can help someone too (it helped me) this is how you select the image you've just added:
这有效,也许以下代码也可以帮助某人(它帮助了我)这就是您选择刚刚添加的图像的方式:
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Select