Downloading images from URLs using vba

R

RandomStu

I have an Excel sheet with vba code that grabs an image from the
internet and inserts it onto the sheet. For example, there's an image
of clothing at

http://www.gap.com/resources/productImage/v1/770868002/P01

(which I can see when I paste the URL into my browser bar). To insert
the image into my workbook, I use code like this:

Sub AddImage()
Dim thePix As Shape
Dim imageURL As String
Dim wks As Worksheet
Dim pasteBelowCell As Range
Set wks = ThisWorkbook.Sheets(1)
Set pasteBelowCell = wks.Range("D8")
imageURL = "http://www.gap.com/resources/productImage/v1/770868002/
P01"
For Each thePix In wks.Shapes
thePix.Delete
Next thePix
Set thePix = wks.Shapes.AddShape(msoShapeRectangle,
pasteBelowCell.Offset(2).Left, _
pasteBelowCell.Offset(2).Top, 120, 140)
Application.DisplayAlerts = False
On Error Resume Next
thePix.Fill.UserPicture imageURL
On Error GoTo 0
Application.DisplayAlerts = True
End Sub
This works beautifully for me. It also works fine pulling in a
different image if I substitute a Canadian URL in the code:

http://www.gapcanada.ca/resources/productImage/v1/848945003/P01

However, when I pass the Excel file to someone in a different network,
they find it works for the US URL, but not the Canadian one. When they
run the code with the gapcanada URL, they get a rectangle with no
image inside.
Please give me any hint of what could be going on.

Many thanks in advance.

(e-mail address removed)
 
M

magmike

I have an Excel sheet with vba code that grabs an image from the
internet and inserts it onto the sheet. For example, there's an image
of clothing at

http://www.gap.com/resources/productImage/v1/770868002/P01

(which I can see when I paste the URL into my browser bar). To insert
the image into my workbook, I use code like this:

Sub AddImage()
    Dim thePix As Shape
    Dim imageURL As String
    Dim wks As Worksheet
    Dim pasteBelowCell As Range
    Set wks = ThisWorkbook.Sheets(1)
    Set pasteBelowCell = wks.Range("D8")
    imageURL = "http://www.gap.com/resources/productImage/v1/770868002/
P01"
    For Each thePix In wks.Shapes
        thePix.Delete
    Next thePix
    Set thePix = wks.Shapes.AddShape(msoShapeRectangle,
pasteBelowCell.Offset(2).Left, _
        pasteBelowCell.Offset(2).Top, 120, 140)
    Application.DisplayAlerts = False
    On Error Resume Next
    thePix.Fill.UserPicture imageURL
    On Error GoTo 0
    Application.DisplayAlerts = True
End Sub
This works beautifully for me. It also works fine pulling in a
different image if I substitute a Canadian URL in the code:

http://www.gapcanada.ca/resources/productImage/v1/848945003/P01

However, when I pass the Excel file to someone in a different network,
they find it works for the US URL, but not the Canadian one. When they
run the code with the gapcanada URL, they get a rectangle with no
image inside.
Please give me any hint of what could be going on.

Many thanks in advance.

(e-mail address removed)

Stu,

It works fine for me with either link. This is likely going to be a
networking/firewall issue. Something in their network is either
blocking them from accessing the canadian site, or blocking the
picture from the canadian site from coming in. This question might be
best addressed in a networking newsgroup.

magmike
 
F

FatBytestard

Stu,

It works fine for me with either link. This is likely going to be a
networking/firewall issue. Something in their network is either
blocking them from accessing the canadian site, or blocking the
picture from the canadian site from coming in. This question might be
best addressed in a networking newsgroup.

magmike

Put zip and unzip routines in. Zip 'em up.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top