Insert image on local drive based on cell name

FatalLordes

Board Regular
Joined
Dec 22, 2017
Messages
76
Office Version
  1. 365
Platform
  1. Windows
Hi all

So I'm sure this is possible and I've tried a few things but for the life of me I cannot get it to work. I need to insert a locally stored image file (C:\Users\My Name\Documents\My Database\Scans) which will change depending on the value of a cell (B3). The image will always end in _vax.jpg, and I've tried "C:\Users\My Name\Documents\My Database\Scans\"&B3&"_VAX.jpg" using a variety of methods, but they all fail. I'm using Excel 365 and locally so can use VBA script if needs be.

Is it really that hard? Or is it because I have spaces in my folder location? If anyone can point me in the right direction, that would be truly appreciated.

Thanks in advance
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
If you go to the folder where you're picture is, select the picture with a single click and then click on the "Copy Path".
If you now paste it in a cell, or directly into the code, is it the same as you have in your code?
BTW, what is in B3? Picture name without the "_VAX.jpg"?
Does it make a difference if you use
Code:
"C:\Users\My Name\Documents\My Database\Scans\" & ActiveSheet.Range("B3").Value & "_VAX.jpg"
What is the rest of the code?
Enlarge the picture to see it all.
 

Attachments

  • Capture.JPG
    Capture.JPG
    5.4 KB · Views: 4
Last edited:
Upvote 0
After you change the path in the following, does that do it?
The sheet where the picture name is in Cell B3 needs to be the ActiveSheet.
Select the cell where you want the top left of the picture to be.
Code:
With ActiveCell
ActiveSheet.Shapes.AddPicture("C:\Users\My Name\Documents\My Database\Scans\" & ActiveSheet.Range("B3").Value & "_VAX.jpg", False, True, .Left, .Top + 2, -1, -1).Name = "Pic" & ActiveCell.Row
End With
 
Upvote 0
So I've got a VBA script that I found that is kinda sorta working but your code is a lot less which appeals to me more. How would I pop that onto the sheet? Would it be the only VBA code? How do I tell it to pop the picture in, say, cell A30? My current script works but I have to manually run the macro each time to make the picture update when I change the name in B3
 
Upvote 0
Re: "How do I tell it to pop the picture in, say, cell A30?"
Read the 3rd line in Post #3 again.

For the rest of your requirements, explain in detail what you would like to happen.
 
Upvote 0

Forum statistics

Threads
1,224,876
Messages
6,181,523
Members
453,051
Latest member
alexbarker2608

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top