【发布时间】:2013-06-14 14:06:43
【问题描述】:
xlApp.activesheet.Pictures.Insert(strImagePath) 将图片作为链接图片插入到电子表格中。如果我将电子表格从我们的网络发送出去,图像就会失败。
如何将图像作为嵌入图像放置?
我也是从 Access 调用这个方法的。
【问题讨论】:
xlApp.activesheet.Pictures.Insert(strImagePath) 将图片作为链接图片插入到电子表格中。如果我将电子表格从我们的网络发送出去,图像就会失败。
如何将图像作为嵌入图像放置?
我也是从 Access 调用这个方法的。
【问题讨论】:
你可以使用shapes.addpicture方法
activesheet.Shapes.AddPicture Filename:="C:\test\desert.jpg", linktofile:=msoFalse, _
savewithdocument:=msoCTrue, Left:=0, Top:=0, Width:=100, Height:=100
【讨论】:
Dim shpPic as Shape 和Set shpPic = xlApp.activesheet.Shapes.AddPicture ...,我得到一个类型不匹配的错误。知道为什么吗?
dim shpPic as Excel.Shape
Excel.Shape,因为我不想引用 Excel 库,因为我的用户拥有大量系统。我这样声明我的 excel 实例:Dim xlApp as ObjectSet xlApp = CreateObject("Excel.Application") 所以我尝试了Dim shpPic = xlApp.Shape,这给了我“未定义用户定义的类型”错误。有什么想法吗?
Dim shpPic as Object 然后使用set shpPic = xlapp.activesheet.shapes.addpicture...
注意,可以将所需的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/
(作为提高知名度的另一个答案添加,因为我多年来一直在努力解决这个问题,并且在其他任何地方都没有发现这个解决方案。)
【讨论】:
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
【讨论】: