Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2010 - resolve image from URL in cell

Status
Not open for further replies.

Brianfree

Programmer
Feb 6, 2008
220
GB
Hi, i am looking for some VBA code to resolve an url image name in CELL A1 to A1000 and place the image in a new cell next to it. If the image does not exist then no image is displayed.

This is what i have so far..

Code:
Sub Test()
    Dim objPicture As Picture
For i = 2 To 100
        With Sheet1.Cells(i, 9)
        Set objPicture = .Parent.Pictures.Insert(Sheet1.Cells(i, 1).Value)
        objPicture.Top = .Top
        objPicture.Left = .Left
        objPicture.Height = 150
        objPicture.Width = 150
    End With
    Next i
End Sub

Please can anyone help?

Many thanks

Brian
 
HI,

Well what happens when you run your code? Please be very specific.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
This might work...
Code:
Sub Test()
    Dim i As Long
    For i = 2 To 100
        Sheet1.Pictures(i - 1).Copy
        Sheet1.Cells(i, 9).PasteSpecial xlPasteAll
        With Sheet1.Pictures(Sheet1.Pictures.Count)
            .Top = .TopLeftCell.Top
            .Left = .TopLeftCell.Left
            .Height = 150
            .Width = 150
       End With
    Next i
End Sub

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
This utility function I've just put together might help:

Code:
[blue]Public Function GetUrlPic(srcUrlcell As Range, targetcell As Range) As String
    On Error GoTo Skip
    With targetcell.Parent.Shapes.AddPicture(srcUrlcell, True, True, targetcell.Left, targetcell.Top, 70, 70)
        .LockAspectRatio = msoTrue
        .ScaleWidth 1, msoTrue, msoScaleFromTopLeft
    End With
Skip:
    On Error GoTo 0
End Function[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top