+ Reply to Thread
Results 1 to 22 of 22

Grab images from URL and insert in cells...

  1. #1
    Registered User
    Join Date
    07-03-2008
    Location
    Sweden
    MS-Off Ver
    Office 2011 for MAC
    Posts
    57

    Grab images from URL and insert in cells...

    Hi,

    I am trying to make an inventory of my wine cellar. I'm using CellarTracker for the cellar management and now need to print out some QR codes to attach to the bottles.

    Anyways, I have exported my cellar to excel so I have all the data, including the barcode for each bottle. I have also generated the unique QR-code URLs for each bottle.

    What I now need to do is write a macro that goes trough row 2 -> last row (currently 63) and grabs the URL from column U and inserts the corresponding picture in column V.

    Is this possible?

    Cheers,

    Marcus

  2. #2
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: Grab images from URL and insert in cells...

    Had to borrow some code from : http://jiwhite.blogspot.be/2009/03/p...-from-url.html

    First things first !!! make a copy of your excel file and test this code in the copy not in your original file !!!

    It will temporarly dowload the pic to a location , so rename the C:\Users\******\Downloads\ to whatever your preferd location is , the pic will be deleted after import anyway.

    So copy the below in a module and update location and then run it.

    Please Login or Register  to view this content.
    Last edited by hulpeloos; 01-21-2013 at 03:40 PM.

  3. #3
    Registered User
    Join Date
    07-03-2008
    Location
    Sweden
    MS-Off Ver
    Office 2011 for MAC
    Posts
    57

    Re: Grab images from URL and insert in cells...

    First of, thanks for the reply.

    I tried copying the code into VBA and changed the location to a folder on my desktop. However when I run the macro I get an error and when I debug it it points towards this row:

    Xvalue = Sheets("Sheet1").Range("B" & Xrow).Value

    Don't know what might be wrong...


    EDIT:

    My bad... realised the sheet name was not "Sheet1" so I changed it and now that error is gone. Now I get another error instead.. pointing to this line:

    DownloadFile = URLDownloadToFile(0&, _
    sSourceURL, _
    sLocalFile, _
    BINDF_GETNEWESTVERSION, _
    0&) = ERROR_SUCCESS

    EDIT ":

    Also tried changing the " Xvalue = Sheets("Sheet1").Range("B" & Xrow).Value" to " Xvalue = Sheets("Sheet1").Range("U" & Xrow).Value"... but that did no difference...
    Last edited by elmaco12; 01-22-2013 at 02:00 PM.

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Grab images from URL and insert in cells...

    All seems a bit complicated to me:
    Please Login or Register  to view this content.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Grab images from URL and insert in cells...

    All seems a bit complicated to me:
    Please Login or Register  to view this content.
    The reason you get the error in the previous code is that it uses code that only exists on windows computers

  6. #6
    Registered User
    Join Date
    07-03-2008
    Location
    Sweden
    MS-Off Ver
    Office 2011 for MAC
    Posts
    57

    Re: Grab images from URL and insert in cells...

    Hi Kyle123,

    Thanks for your post. It seams a bit complicated to me as well, I am very grateful for the geniuses that reside in this forum

    I tried your code but I get an error with that one as well. This time the debugger points to "With .Pictures.Insert(oCell.Value)"

    Do you have any suggestion to why this happens?

    Thank you

    /Marcus

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Grab images from URL and insert in cells...

    Are the urls in the U column valid? what do they look like?

    It might be a mac thing, but I can't check since I don't have office on my mac.

  8. #8

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Grab images from URL and insert in cells...

    What's the error message? Is it - Unable to Get the Insert Property of the Pictures class?

  10. #10
    Registered User
    Join Date
    07-03-2008
    Location
    Sweden
    MS-Off Ver
    Office 2011 for MAC
    Posts
    57

    Re: Grab images from URL and insert in cells...

    "Run-time error '1004':

    Unable to get the Insert property of the Pictures class"

    And when I click Debug it just points to ".Pictures.Insert(oCell.Value)"

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Grab images from URL and insert in cells...

    Do the hyperlinks appear truncated as above (with the ... in them)? Or do you see the full link which has a reference to cellartracker in?

    Try this, although your second link doesn't appear to be valid:
    Please Login or Register  to view this content.
    Last edited by Kyle123; 01-24-2013 at 10:42 AM.

  12. #12
    Registered User
    Join Date
    07-03-2008
    Location
    Sweden
    MS-Off Ver
    Office 2011 for MAC
    Posts
    57

    Re: Grab images from URL and insert in cells...

    The links appear complete in excel. Without the "..." in them.

    What do you mean not valid? They all seam to work for me (i get a qr-code when clicking on each of them..)

    I tried the new code. Now I get a different error:

    "Run-time error '9':

    Subscript out of range"

    The debugger points to: "With .Pictures.Insert(oCell.Hyperlinks(1).Address)"

  13. #13
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Grab images from URL and insert in cells...

    Ok, think it's time for you to upload a sample workbook

  14. #14
    Registered User
    Join Date
    07-03-2008
    Location
    Sweden
    MS-Off Ver
    Office 2011 for MAC
    Posts
    57

    Re: Grab images from URL and insert in cells...

    hmm, found something strange now. If I click the link in excel i get to a page that just shows:

    "‰PNG  IHDR^^BIMbKGD “-IDATxœn6@ѸC<†V*8K}|~~o‘4A€ @ Hi‚4A€ @ Hi‚4A€ @ Hi‚4A€ @ Hi‚4A€ @ Hi‚4 ˜…™}W–]ٽŸ>u<?j‚4A€ @ Hs +SSžšX9=Gpye€ @ Hi½s +S5n›#8=pe€ @ HiwŸž\~ai‚4A€ @ H5|~;/pz><%€ @ Hinž:`~ X5A€ @ H„{޲O>„x/ž–X5A€ @ H„O›šwu{1ž:Ÿ‚?di‚4A€ @ HNN>69 +S{@V^X5A€ @ H„{n~s_x˹žš˸‡ii‚4A€ @ Hkx‹/oSM<y w @ HiX:–zj?…]S›_Xj‚4A€ @ H5œž?Ÿ•)n3=ŸV @ Hi‚4a†wŸy+Œ׹yxœUi‚4A€ @†•ӿ{œ…—au&Lj‚4A€ @ H5<‡•8}Ž#vv<…Ui‚4A€ @w-OAL|m8 Hi‚4A€p{(N~Š}׹€kAj‚4A€ @ Hž”‰x=SX9}?2ƒj‚4A€ @ Ha~}Ÿ~?箾/N›<5We€ @ Hi{(o߯2u׹†]‡˪i‚4A€ @ oa}sN›š_˜zv?Ϊi‚4A€ @ 5:z9SsSngi‚4A€ @ Hkm~}޿pƒ›n{ii‚4A€ @ H~N‚]S0u{N <|V @ Hi‚4a~awŸ|w˜š;8=}~†\{.ŠUi‚4A€ @˜ŸkxWϧ8Ͽw~GxŠUi‚4A€ @˜ŸkXm{y SS5uŽqV @ Hi‚4޹†•WOL}+Okœž›8=W2Ϊi‚4A€ @ o6S–k/M;—aŪi‚4A€ @ ˜kjžL}ofNa—Ui‚4A€ @x\[wO“Ÿ>|ž~ɵV @ Hi‚4޹†7a?4uS|ʵƒUi‚4A€ @v[di‚4A€ @ Hi‚4A€ @ Hi‚4A€ @ Hi‚4A€ @ Hi‚4A€ @ Hig†IENDB`‚"

    But if i then click in the address bar and then hit enter, the page reloads and the qr-code shows. (I have to click in the address bar and then press enter, just refreshing with cmd+r does not work...)

  15. #15
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Grab images from URL and insert in cells...

    Ok, please post a sample workbook

  16. #16
    Registered User
    Join Date
    07-03-2008
    Location
    Sweden
    MS-Off Ver
    Office 2011 for MAC
    Posts
    57

    Re: Grab images from URL and insert in cells...

    Here comes the workbook
    Attached Files Attached Files

  17. #17
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Grab images from URL and insert in cells...

    I think the problem is that you have a mixture of hyperlinks (as Excel understands them) and urls that Excel hasn't converted to hyperlinks yet.

    This worked for me for all your items:
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    07-03-2008
    Location
    Sweden
    MS-Off Ver
    Office 2011 for MAC
    Posts
    57

    Re: Grab images from URL and insert in cells...

    Seams like only the first url is a hyperlink and the rest is just text, right?

    I tried running that macro but get the same error as the first time now.

    Debugger points to: "With .Pictures.Insert(address)"

    Where do you place the marker when you run the macro? Or does that not matter?

    /Marcus

  19. #19
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Grab images from URL and insert in cells...

    It doesn't matter, but unless you tell me what the error message actually is, I'm shooting in the dark - Which is "the first time" error message?

  20. #20
    Registered User
    Join Date
    07-03-2008
    Location
    Sweden
    MS-Off Ver
    Office 2011 for MAC
    Posts
    57

    Re: Grab images from URL and insert in cells...

    error message:

    "Run-time error '1004':

    Unable to get the Insert property of the Pictures class"

    Debugger points to the line with: "With .Pictures.Insert(address)"

  21. #21
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Grab images from URL and insert in cells...

    Then honestly, I've got no idea. It might be a mac thing but I'd guess not since Pictures.Insert has been around a very long time.

    I'll ask to see if someone with mac office can have a look

  22. #22
    Registered User
    Join Date
    07-03-2008
    Location
    Sweden
    MS-Off Ver
    Office 2011 for MAC
    Posts
    57

    Re: Grab images from URL and insert in cells...

    Thanks Kyle123, I really appreciate it.

    I found this link (http://stackoverflow.com/questions/1...ba-excel-shape) with has a similar issue. I quote:

    "I've used a small subroutine to insert a picture into my sheet by
    ActiveSheet.Pictures.Insert(URL).Select
    This works fine with Excel 2003 (Windows), but does not work with Excel 2011 (Mac) any more."


    It then goes on to explain another method, but it is to advanced for me. They use something that looks like theShape.Fill.UserPicture URL.

    Further down in the code it looks like this:

    "' Create a Shape for putting the Image into
    ' ActiveSheet.Pictures.Insert(URL).Select is deprecated and does not work any more!!!
    Set theShape = wks.Shapes.AddShape(msoShapeRectangle, pasteCell.Left, pasteCell.Top, 200, 200)

    ' fill the shape with the image after greening
    theShape.Fill.BackColor.RGB = RGB(0, 255, 0)
    theShape.Fill.UserPicture URL
    "

    Does this make sense to you?

    EDIT:
    also saw that they start the code by defining theShape as shape: "Dim theShape As Shape"

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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