VBA code for Inserting an Image

Closed
adikademani
Posts
6
Registration date
Monday October 24, 2016
Status
Member
Last seen
November 24, 2016
- Oct 24, 2016 at 04:14 PM
 Blocked Profile - 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

3 replies

Blocked Profile
Oct 24, 2016 at 05:04 PM
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.
0
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
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
captainashish
Posts
20
Registration date
Thursday May 12, 2016
Status
Member
Last seen
November 28, 2016

Oct 25, 2016 at 05:10 AM
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
0
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
0
Blocked Profile
Oct 26, 2016 at 05:03 PM
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"
0