Insert images into respective cells according to filepaths stored in a range

Almir's picture

Here is a macro to insert image files into respective cells, according to image filenames or full filepaths.
File names/paths are stored in "D" column, and pictures are inserted in "A" column, in the same row.

If you have only the list of file names, use the first macro ("Short Name"). Change the macro so it refers to the folder where image files are stored.

If you have a list of image files as full path+filename, use the second macro ("Full Path").

I recommend using the second method.

To keep your list of image files updated, use this:

Look at attached example to see how it works.

Insert images into cells according to file names stored in a range
InsertPicturesIntoCells.xlsm21.67 KB

Keep the code running


Thanks for your example on your Post: "Insert images into respective cells according to filepaths stored in a range" This saved me hours of work.

However, is there a way to modify the code so that it keeps running even if it doesn't find a picture in the folder ? ... I get a Debug message when this happens and the code stops running.

Any help is much appreciated.

Almir's picture

Use "On Error Resume Next"

Insert a line containing "On Error Resume Next" before:
"Set myPicture = ActiveSheet.Pictures.Insert(pic)".
However, I would recommend you to use solution described at:, in order to have your file list updated, so you avoid situation that you get an error.


Thanks a lot Almir, I inserted the line and the code works beautifully.


Almir, I think that I was a little quick on yelling success.

Turns out that when I use the line "On error Resume Next", the code runs itself through and gets me all of the available pictures but places many of them in the wrong cell ... some 1 cell lower, some as low as 13 cells lower.

The code seems to indicate to look up the name of the file in the D column and place the picture (if found) in the adjacent A column.

Since I have several pictures missing in my folder, could this be one of the reasons ?

Almir's picture

What file do you use?

Do you use full path names?