Search code examples
excelcomimageautomation

Is is possible to insert an image into an excel cell via COM?


I have used automation to insert values into a cell, however I have never seen any documentation, for example, that demonstrate inserting anything other than text and/or formula's.

Has anybody been able to insert an image from an external application?


Solution

  • Dim FileName as string
    FileName="c:\text.jpg"
    Set NewPic = ActiveSheet.Pictures.Insert(FileName)
    NewPic.top=100
    NewPic.left=100
    

    If you want to position the picture to a specific cell then select that cell as a range and use that ranges top/left/with to position the picture.

    Samples: http://exceltip.com/st/Insert_pictures_using_VBA_in_Microsoft_Excel/486.html

    Note: In Excel cells cannot contain pictures. The pictures live on an invisible drawing layer that floats about the cells. They can be positioned based on the cell coordinates, which makes it feel like they are living "in" the cells.