Insert images into respective cells according to filepaths stored in a range
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: http://www.excelexperts.com/VBA-Tips-List-Files-In-A-Folder.
Look at attached example to see how it works.
Attachment | Size |
---|---|
InsertPicturesIntoCells.xlsm | 21.67 KB |
- Almir's blog
- Login or register to post comments
- 32506 reads
Keep the code running
Almir,
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.
Use "On Error Resume Next"
Petipiti,
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:
http://www.excelexperts.com/VBA-Tips-List-Files-In-A-Folder, in order to have your file list updated, so you avoid situation that you get an error.
WORKS GREAT
Thanks a lot Almir, I inserted the line and the code works beautifully.
NEW PROBLEM
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 ?
What file do you use?
Do you use full path names?