VBA code for Inserting an Image [Closed]

Posts
6
Registration date
Monday October 24, 2016
Status
Member
Last seen
November 24, 2016
- - Latest reply: ac3mark
Posts
13031
Registration date
Monday June 3, 2013
Status
Moderator
Last seen
October 11, 2019
- Oct 26, 2016 at 05:03 PM
Hi guys,

I am in an urgent need for a command or code to insert an image from any directory in my computer to a particular cell in Excel using VBA. For example, i have a .jpg file named ABK in my E:Drive and i want to get that pic to a cell A1 in Excel when it corresponds to the value ABK in cell B1.

Your guidance is appreiciated:)

Thanks
See more 

3 replies

Posts
13031
Registration date
Monday June 3, 2013
Status
Moderator
Last seen
October 11, 2019
1571
0
Thank you
So, is the file path going to dynamic? Meaning, will it always be stored in the same place, and called the same thing?

Post your code and we can help, we cannot produce code turn key for you.
Hi ac3mark, Actually i am new to VBA, i just want to know what command can be used to call a specific picture from the hard drive. I do not have any code as such. Looking forward for you guidance . thanks:)
0
Thank you
Hi ac3mark,

Actually i am new to VBA, i just want to know what command can be used to call a specific picture from the hard drive. I do not have any code as such. Looking forward for you guidance . thanks:)
Posts
20
Registration date
Thursday May 12, 2016
Status
Member
Last seen
November 28, 2016
0
Thank you
Hello,

To insert a selected picture in excel:
ActiveSheet.Pictures.Insert('full path of the picture from your local drive')  

The above code will simply insert selected picture in excel within the selected cell or range in its original size.

Thanks & Regards,
Captain Ashish
Hi Captainashish,

Thanks for the quick reply. I used that command as below. The file gets inserted into the selected cell but it does not get displayed. It just says "the linked image cannot be displayed. The file may have been moved,renamed or deleted." I tried the command with different pictures inn different folders, but still it shows the same message.

Looking forward for your guidance :)


Sub pics()

ActiveSheet.Pictures.Insert ("C:\Users\Public\Pictures\Sample Pictures\")

End Sub
ac3mark
Posts
13031
Registration date
Monday June 3, 2013
Status
Moderator
Last seen
October 11, 2019
1571 -
This is why i don't do turn key solutions. If we helped and guided you to the solution, you would learn. Just posting some cut and paste scripts, ALWAYS ends up with:

"IT doesn't work!"

Your path has no Image file attached to it:"C:\Users\Public\Pictures\Sample Pictures\"

that is a folder path. it should be: "C:\Users\Public\Pictures\Sample Pictures\imagefile.png"