Using VBA to insert and keep images in file - Excel 2013 Using VBA to insert and keep images in file - Excel 2013 vba vba

Using VBA to insert and keep images in file - Excel 2013


In all my uses, Adding a picture with Insert makes a reference to a file on your harddrive, for whatever reason if you want the image to be embedded in the file you have to add a shape and then put the image on the shape using the AddPicture (like you use), I have never had any issues with this.

Also you are giving the picture a height and width of 1 pixel, You will almost never be able to see that true setting that higher as below:

Application.ActiveSheet.Shapes.AddPicture "C:\documents\somepicture.jpg", False, True, 1, 1, 100, 100

I have a feeling it was working all along and you just never saw the picture cause it was too small.


The first snippet works just fine, but it does not allow picture positioning (i.e. if you need a pic placed at some certain range), so I made something that works nicely with positioning available, based on the second solution, such as it is shown below.

Dim r As RangeDim pic As ShapeSet r = ActiveSheet.Range("A34:Q58")Set pic = ActiveSheet.Shapes.AddPicture(ThisWorkbook.Path & "\FracAnalysis.png", _linktofile:=msoFalse, savewithdocument:=msoCTrue, Left:=0, Top:=0, Width:=-1, Height:=-1)With pic   .LockAspectRatio = msoFalse   .Top = r.Top   .Left = r.Left   .Width = r.Width   .Height = r.HeightEnd with


Previous answer has been really useful! I just wanted to add the reference to the method parameters (I thought the width and height were in pixels, turns out they're in points):

https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.shapes.addpicture.ASPX