Closed Thread
Results 1 to 32 of 32

Insert the first image found with image search (e.g google) with criteria taken from cell.

  1. #1
    Registered User
    Join Date
    10-29-2014
    Location
    Uk
    MS-Off Ver
    2007 and 2013
    Posts
    16

    Insert the first image found with image search (e.g google) with criteria taken from cell.

    Hi all
    So I am making a spreadsheet that inserts an image based on what cell B2 contains e.g I put in salmon, hopefully I get an image of a salmon. So far I have the following

    Dim URL As String
    URL = "https://www.google.co.in/search?q=" & Cells(2, 2) & "&source=lnms&tbm=isch&sa=X" & "&rnd=" & WorksheetFunction.RandBetween(1, 10000)
    Sheets(1).Shapes.AddPicture URL _
    , msoFalse, msoTrue, 100, 100, 50, 50

    Now the URL gets me the image result page for Google images but that's not good enough, I need the first result from the search (or the second or third- it doesn't really matter which one, it only matters that I get a result at all). The second line inserts the image as needed but without a working link, its all for nothing.

    I don't need to use Google images- I am happy to use any search engine that will return me a image related to the search criteria. Ideally I would just use the built in online pictures part of excel but recording a macro with that doesn't work (it just points at the temp image file that is created).

    Any ideas would be gratefully received.
    Many thanks

  2. #2
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    duplicate post http://www.excelforum.com/excel-prog...using-vba.html

  3. #3
    Registered User
    Join Date
    10-29-2014
    Location
    Uk
    MS-Off Ver
    2007 and 2013
    Posts
    16

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Oh, I had not spotted that. Thanks I will bump that thread instead.

  4. #4
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    hi

    check this code

    Please Login or Register  to view this content.
    Cheers!

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,840

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    In addition to Excelliot's code
    try this little change
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  6. #6
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    My earlier code was not fetching first image, use this to fetch..

    Requirements In Column A write name of object for which you want image search, In B column you will get URL of source image & in C column you will get Image matching size of your cell, you can re-size your C column to make your image bigger or smaller before running macro..

    Please Login or Register  to view this content.
    Cheers!!

  7. #7
    Registered User
    Join Date
    10-29-2014
    Location
    Uk
    MS-Off Ver
    2007 and 2013
    Posts
    16

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Well this solves everything, thanks so much guys. I suspect it will take me a while to understand how the code works but both of you have provided working solutions for something the internet didn't seem to know how to do so hats off! Thanks again

  8. #8
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Repeat of earlier..Ignore

  9. #9
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Quote Originally Posted by themob212 View Post
    Well this solves everything, thanks so much guys. I suspect it will take me a while to understand how the code works but both of you have provided working solutions for something the internet didn't seem to know how to do so hats off! Thanks again
    Great this worked for you, Cheers!!

  10. #10
    Registered User
    Join Date
    05-11-2016
    Location
    OTA
    MS-Off Ver
    2010
    Posts
    10

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Hi everyone, thank you very much for your help! the code is great but I get an error

    I think the error is due to the format %33%A... of the fetched link: http%3A%2F%2Fweknowyourdreamz.com%2Fimages%2Fbaby%2Fbaby-02.jpg

    can you help please?

  11. #11
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Quote Originally Posted by Vincent121 View Post
    Hi everyone, thank you very much for your help! the code is great but I get an error

    I think the error is due to the format %33%A... of the fetched link: http%3A%2F%2Fweknowyourdreamz.com%2Fimages%2Fbaby%2Fbaby-02.jpg

    can you help please?
    what keyword you tried?

  12. #12
    Registered User
    Join Date
    05-11-2016
    Location
    OTA
    MS-Off Ver
    2010
    Posts
    10

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    In the example I posted I tried with "baby" keyword. I found a workaround by coding the following piece of code but it seems to create some errors 10-15% of the time:

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    See revised code you will get proper decoded url:

    Please Login or Register  to view this content.
    Cheers!!

  14. #14
    Registered User
    Join Date
    05-11-2016
    Location
    OTA
    MS-Off Ver
    2010
    Posts
    10

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    wow thank you! that's the first time I ask anything on a forum and I didn't expect such a fast and accurate reply
    it works perfectly!

    do you know how if a macro exist to delete all the pictures?

  15. #15
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Quote Originally Posted by Vincent121 View Post
    wow thank you! that's the first time I ask anything on a forum and I didn't expect such a fast and accurate reply
    it works perfectly!

    do you know how if a macro exist to delete all the pictures?
    Oh thats amazing..

    try below code to clear all images, drawing objects

    Please Login or Register  to view this content.
    If you only want to delete pictures do buzz

    Cheers!!

  16. #16
    Registered User
    Join Date
    05-11-2016
    Location
    OTA
    MS-Off Ver
    2010
    Posts
    10

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    working like a charm, thanks a million

    have a good day

  17. #17
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Thats great.. good day, keep posting.

  18. #18
    Registered User
    Join Date
    01-07-2004
    Posts
    1

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Hi

    I used this code last week and it worked well.

    However, this week for the same search terms i am now never getting a match for the "furl = InStrRev(url2, "&imgrefurl=", -1)". the aElement.href doesnt seem to contain "&imgrefurl=" in any of the searches?

    Has something changed in the IE language?

    Thanks

    Nigel

  19. #19
    Registered User
    Join Date
    06-18-2016
    Location
    Bulgaria
    MS-Off Ver
    2013
    Posts
    1

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    This is an awesome script!

  20. #20
    Registered User
    Join Date
    10-21-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    I get complie error 5 with this code, can anybody help me?

    Thanks

  21. #21
    Registered User
    Join Date
    12-02-2017
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    2016
    Posts
    2

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Besides Microsoft Internet Control and HTML object library should i add any other reference? I am using this code on a database of 2500 items. After 200 its giving me error "Application defined or object defined error"? is there anything I am doing wrong??

  22. #22
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    11,846

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    ahver,
    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Ben Van Johnson

  23. #23
    Registered User
    Join Date
    02-13-2019
    Location
    San Jose
    MS-Off Ver
    Office 2016
    Posts
    4

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Hi friends

    I found a VBA code to help me Insert the first image found with image search (e.g google) with criteria taken from cells. This code from 'excelliot' help me so much things, but can you help me to solve the problem that "if a picture is not found, or the keyword mismatch with google image search result, or there is some error that 1st picture, the code will ignore the 1st picture and will picked 2nd picture to replace the 1st one" and also if the error still there with the 2nd picture, the code will ignore the error cell value and continue with the next value? Because I got the error code:

    Please Login or Register  to view this content.
    An when I clicked on to Debug button, it's pointed to this line:
    Please Login or Register  to view this content.
    Thank

  24. #24
    Registered User
    Join Date
    02-13-2019
    Location
    San Jose
    MS-Off Ver
    Office 2016
    Posts
    4

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    I found the problem came from source of pictures. Some source pictures from Amazon, Amazonaws, shopify... cant fetch the pictures and the code result error. If I add the exclude keywords in the code, the code will work without any problem. Like this:

    Please Login or Register  to view this content.
    to exclude the result from amazon.com and amazonaws, I added: "+-amazon+-amazonaws" to "&source=lnms&tbm=isch&sa=X&rnd=1", that will be:

    Please Login or Register  to view this content.
    Can we code the max request time for download picture, in case if the pictures cannot finish download in 20 seconds will be skip to the 2nd link...? Because sometimes I waited to download a picture cost about 5 6mins but we can save a lot of time with the 2nd link, it cost only 5secs. Thank

  25. #25
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 2000/3/7/10/13/16/365
    Posts
    52,013

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    sairy welcome to the forum

    Unfortunately your post does not comply with Rule 4 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  26. #26
    Registered User
    Join Date
    02-13-2019
    Location
    San Jose
    MS-Off Ver
    Office 2016
    Posts
    4

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Thank to notice, I will read and follow the rules.

  27. #27
    Registered User
    Join Date
    09-05-2019
    Location
    denmark
    MS-Off Ver
    10
    Posts
    3

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Is there anybody who has an Excel, where it works?
    I've tried to apply it here, but it doesnt work.

    So if anybody has a spreadshet where it works, please send it

    Im also looking for the same solution.

    Row A Row B
    Tesla p-85 (picture of it)

    ETC

  28. #28
    Registered User
    Join Date
    08-27-2018
    Location
    Auckland
    MS-Off Ver
    365
    Posts
    1

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Im getting Run-time error '5': Invalid procedure call or argument

    furl = Mid(ur12, 40, furl - 40)

  29. #29
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 2000/3/7/10/13/16/365
    Posts
    52,013

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Quote Originally Posted by anonsky1 View Post
    Im getting Run-time error '5': Invalid procedure call or argument

    furl = Mid(ur12, 40, furl - 40)
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread

  30. #30
    Registered User
    Join Date
    03-02-2020
    Location
    mexico
    MS-Off Ver
    excel 2010
    Posts
    1

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    hi! sorry, could you please post a working worksheet with this code? i just cant make it

  31. #31
    Registered User
    Join Date
    04-13-2021
    Location
    Bentonville, AR
    MS-Off Ver
    2020
    Posts
    2

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Same, get an error at furl with Run-time error '5': Invalid procedure call or argument

  32. #32
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Ipswich, England
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel (Windows 11 64-bit)
    Posts
    62,194

    Re: Insert the first image found with image search (e.g google) with criteria taken from c

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" to anyone who has offered you help in your thread. You can reward them by clicking on * Add Reputation below theur user name on the left, if you wish.


    Forum Rules (updated September 2018): please read them here.
    How to use the Power Query code you've been given: help here. More about the Power suite here.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Autoimport Google Image Search Result into Excel
    By awesummusik in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-14-2021, 12:29 PM
  2. Return first image link from google search in excel using vba
    By vivis in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 03-06-2021, 02:23 AM
  3. Google image search from cell contents of excel file
    By merQrey in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 07-24-2020, 01:01 AM
  4. Replies: 0
    Last Post: 07-08-2014, 06:27 AM
  5. Insert image and image name into specific place on sheet
    By ACE23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-05-2014, 04:41 AM
  6. [SOLVED] Insert jpg image from file path to image frame
    By SAsplin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-27-2012, 10:12 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1