【问题标题】:How to insert an embedded picture?如何插入嵌入的图片?
【发布时间】:2013-06-14 14:06:43
【问题描述】:

xlApp.activesheet.Pictures.Insert(strImagePath) 将图片作为链接图片插入到电子表格中。如果我将电子表格从我们的网络发送出去,图像就会失败。

如何将图像作为嵌入图像放置?

我也是从 Access 调用这个方法的。

【问题讨论】:

    标签: excel vba ms-access


    【解决方案1】:

    你可以使用shapes.addpicture方法

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

    【讨论】:

    • 谢谢@JosieP!这很好用。现在我正在尝试将其分配给 Shape 对象,以便进行一些调整。我做了Dim shpPic as ShapeSet shpPic = xlApp.activesheet.Shapes.AddPicture ...,我得到一个类型不匹配的错误。知道为什么吗?
    • 基于 xlApp 部分我猜你是从另一个应用程序自动化 - 该应用程序是否有 Shape 对象?如果是这样,请使用dim shpPic as Excel.Shape
    • 嗨@JosieP,是的,我是从 Access 打来的。我不能使用Excel.Shape,因为我不想引用 Excel 库,因为我的用户拥有大量系统。我这样声明我的 excel 实例:Dim xlApp as ObjectSet xlApp = CreateObject("Excel.Application") 所以我尝试了Dim shpPic = xlApp.Shape,这给了我“未定义用户定义的类型”错误。有什么想法吗?
    • 如果你是后期绑定 excel,你必须声明为 Object
    • 不是你Dim shpPic as Object 然后使用set shpPic = xlapp.activesheet.shapes.addpicture...
    【解决方案2】:

    注意,可以将所需的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/

    (作为提高知名度的另一个答案添加,因为我多年来一直在努力解决这个问题,并且在其他任何地方都没有发现这个解决方案。)

    【讨论】:

      【解决方案3】:
      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-28
        • 1970-01-01
        • 2018-05-10
        • 1970-01-01
        • 1970-01-01
        • 2012-03-31
        相关资源
        最近更新 更多