+ Reply to Thread
Results 1 to 22 of 22

Grab images from URL and insert in cells...

Hybrid View

elmaco12 Grab images from URL and... 01-21-2013, 02:18 PM
hulpeloos Re: Grab images from URL and... 01-21-2013, 03:38 PM
elmaco12 Re: Grab images from URL and... 01-22-2013, 01:54 PM
Kyle123 Re: Grab images from URL and... 01-24-2013, 08:49 AM
Kyle123 Re: Grab images from URL and... 01-24-2013, 08:48 AM
elmaco12 Re: Grab images from URL and... 01-24-2013, 10:19 AM
Kyle123 Re: Grab images from URL and... 01-24-2013, 10:26 AM
elmaco12 Re: Grab images from URL and... 01-24-2013, 10:28 AM
Kyle123 Re: Grab images from URL and... 01-24-2013, 10:35 AM
elmaco12 Re: Grab images from URL and... 01-24-2013, 10:38 AM
Kyle123 Re: Grab images from URL and... 01-24-2013, 10:39 AM
elmaco12 Re: Grab images from URL and... 01-24-2013, 10:52 AM
elmaco12 Re: Grab images from URL and... 01-24-2013, 10:54 AM
elmaco12 Re: Grab images from URL and... 01-24-2013, 10:48 AM
Kyle123 Re: Grab images from URL and... 01-24-2013, 10:51 AM
Kyle123 Re: Grab images from URL and... 01-24-2013, 10:53 AM
Kyle123 Re: Grab images from URL and... 01-24-2013, 10:59 AM
elmaco12 Re: Grab images from URL and... 01-24-2013, 11:03 AM
Kyle123 Re: Grab images from URL and... 01-24-2013, 11:07 AM
elmaco12 Re: Grab images from URL and... 01-24-2013, 11:12 AM
Kyle123 Re: Grab images from URL and... 01-24-2013, 11:15 AM
elmaco12 Re: Grab images from URL and... 01-24-2013, 11:22 AM
  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.

    Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" _
    (ByVal pCaller As Long, _
    ByVal szURL As String, _
    ByVal szFileName As String, _
    ByVal dwReserved As Long, _
    ByVal lpfnCB As Long) As Long
    Private Const ERROR_SUCCESS As Long = 0
    Private Const BINDF_GETNEWESTVERSION As Long = &H10
    Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
     
    Public Function DownloadFile(sSourceURL As String, _
        sLocalFile As String) As Boolean
        DownloadFile = URLDownloadToFile(0&, _
        sSourceURL, _
        sLocalFile, _
        BINDF_GETNEWESTVERSION, _
        0&) = ERROR_SUCCESS
         
    End Function
    
    Sub picimport()
    For X = 1 To 100
        Dim Xrow As String
        Dim Xvalue As String
        Xrow = X
        Xvalue = Sheets("Sheet1").Range("B" & Xrow).Value
            If Xvalue = "" Then
                Exit Sub
            Else
        Dim sURL As String
        Dim sLocalFile As String
        Dim sDestination As String
        Dim sText As String
        sText = Xvalue
        sURL = sText
        sLocalFile = "C:\Users\******\Downloads\test.png"
        DownloadFile sURL, sLocalFile
        
                Set pic = ActiveSheet.Pictures.Insert("C:\Users\******\Downloads\test.png")
                Sheets("Sheet1").Range("V" & Xrow).Select
                If Not pic Is Nothing Then
                Set Rng = ActiveCell
                With pic
                .Height = Rng.Height
                .Width = Rng.Width
                .Left = Rng.Left
                .Top = Rng.Top
                End With
                End If
            End If
    Kill "C:\Users\******\Downloads\test.png"
    Next X
    End Sub
    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,239

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

    All seems a bit complicated to me:
    Sub Macro1()
    Dim oCell As Range
        With Sheets("sheet1")
            For Each oCell In .Range("U2:U100")
              With .Pictures.Insert(oCell.Value)
                .Top = oCell.Top
                .Height = oCell.Height
                .Left = oCell.Offset(, 1).Left
              End With
            Next oCell
        End With
    End Sub
    The reason you get the error in the previous code is that it uses code that only exists on windows computers

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

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

    All seems a bit complicated to me:
    Sub Macro1()
    Dim oCell As Range
        With Sheets("sheet1")
            For Each oCell In .Range("U2:U100")
              With .Pictures.Insert(oCell.Value)
                .Top = oCell.Top
                .Height = oCell.Height
                .Left = oCell.Offset(, 1).Left
              End With
            Next oCell
        End With
    End Sub

  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,239

    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,239

    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,239

    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:
    Sub Macro1()
    Dim oCell As Range
        With Sheets("sheet1")
            For Each oCell In .Range("U2:U100")
              With .Pictures.Insert(oCell.Hyperlinks(1).Address)
                .Top = oCell.Top
                .Height = oCell.Height
                .Left = oCell.Offset(, 1).Left
              End With
            Next oCell
        End With
    End Sub
    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...

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

    "‰PNG  IHDR^^BIàMbKGDÿÿÿ ½§“-IDATxœíÝÑnÜ6@ѸÈÿÿ²ûÜà²ÑC¹ç<†VØ*8K}|~~þø§¿¦o¸‘4A€ @ H¤Òi‚4A€ @ H¤Òi‚4A€ @ H¤Òi‚4A€ @ H¤Òi‚4A€ @ H¤Òi‚4áçô üøøø˜¾…ßòùù™ÿ}÷þW×Ùõ–Ï]Ù½ŸÕç>uÛ<õÿë?³j‚4A€ @ H¤ós +SûºS󻞚³X9=Gpúú»×yËóöe¬€ @ H¤Òi½s +S笼偧æ5n›#8=pÛóöe¬€ @ H¤ÒiÂûæÞâôþÿîõw÷矺þéóžú\~aÕi‚4A€ @ HÌ5|µÛ~ÿ¿;/pz>Â<Â%¬€ @ H¤ÒiÂûænÛ÷ž:¿`÷~¦æ Þî¶çíËX5A€ @ H¤Ò„{çÞ²O>õÞ„Óï§xËû/žò–çíËX5A€ @ H¤Ò„ÿíÏÑO›šwØuÛ{1ž:Ÿ‚?dÕi‚4A€ @ HæçNÿNþ©÷>Ü6°ëô9 +SßÛÔ{@V^÷üX5A€ @ H¤Ò„{çnÛ~ês§Î_x˹»žšË¸íûÿ‡iÕi‚4A€ @ Hîkx‹ñ/ðÞoêúSçM<Åy Àw @ H¤ÒiÂÏéX:½ü–ëìzj?ü¶ù…]Só¯›_X±j‚4A€ @ H¤óç5¬œÞžÚ?Ÿúû•Ûæ)n3õ=ŸV @ H¤Òi‚4aþ¼†§öÕw÷Ÿ¿ëy+§ïÿ¶¹ŒÓ×¹íyxœU¤Òi‚4A€ @¸÷¼†•Ó¿{¿íœ…·¿—a×éòuç&L±j‚4A€ @ H¤óç5¬<µÿú‡•ÓïÑ8}ŽÀ®Ûæ#vÝvþÅø<…U¤Òi‚4A€ @¸w®á-çÿOÍAL½¿ãôüÂÔ|ÄmÏÕ8« H¤Òi‚4A€pï{(Nïßö~ŠÝÏ}ÊÔý×¹€kÿAí²j‚4A€ @ H¤÷ž×ð”©ýóÛΉxê=Sï×X9}?§ç2®ƒ°j‚4A€ @ H¤ß®a×î~õé}ìÝëŸ~?ÅÔ箾·§æ/NÏ›<5Wòe¬€ @ H¤ÒiÂü{(¼oâ߯³2uýÓ×¹í¼†ÝÏ]ÿ‡¶ËªÒi‚4A€ @ ¼o®aêüÿ©}ì©sN›š_˜zÞv¯?ΪÒi‚4A€ @ ÌÏ5ì:ýûü©ëïzË9SsS¦ængÕi‚4A€ @ Hîk¸m~á¶}éÛÞ¿píƒô›n{ÿÈø÷iÕi‚4A€ @ H~NßÀñù‚]§ßS0uÞÁÔ{NÏ Üö<|V @ H¤Òi‚4a~®awŸ|üw쿘š;8ý=¼}~á¶÷†\{.ÊU¤Òi‚4A€ @˜ŸkxËïáWûϧÏ8½Ï¿ºÎwÝÏê~®GxŠU¤Òi‚4A€ @˜ŸkX¹mß{×Ôy SóSï×Ø5uŽÃéïóqV @ H¤Òi‚4áÞ¹†•·ÌìîWOÍL}+OÍkœž›8=W2ΪÒi‚4A€ @ ¼o®á6Sûç»ÿ–ýökÏ/øM¯;—aŪÒi‚4A€ @ ˜køj·½Çá©óžúûÕýL}oßfNa—U¤Òi‚4A€ @xß\Ã[öw÷ÃOï“Ÿ>Çáô|ÄÔçž~ïɵóV @ H¤Òi‚4áÞ¹†·¼7aåÚýê?4uÞÁS¿ëô|ʵσU¤Òi‚4A€ @ø¸v[dÕi‚4A€ @ H¤Òi‚4A€ @ H¤Òi‚4A€ @ H¤Òi‚4A€ @ H¤Òi‚4A€ @ H¤ÒiÂßg†óß«¿÷IEND®B`‚"

    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...)

  13. #13
    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

  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...

    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)"

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

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

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

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

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

    Ok, please post a sample workbook

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

    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:
    Sub Macro1()
    Dim oCell As Range
    Dim address As String
        With Sheets("sheet1")
            For Each oCell In .Range("U2:U100")
             If oCell.Hyperlinks.Count > 0 Then
               address = oCell.Hyperlinks(1).address
             Else
               address = oCell.Text
             End If
              With .Pictures.Insert(address)
                .Top = oCell.Top
                .Height = oCell.Height
                .Left = oCell.Offset(, 1).Left
              End With
            Next oCell
        End With
    End Sub

  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,239

    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,239

    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