VBA: import img source from list of URLs

mike93

New Member
Joined
May 16, 2018
Messages
3
Hey all,

This is my first post to Mr.Excel, so let me know if I can do anything to improve this post.

Im new to VBA and am stuck on a project I've taken on.

Im trying to use VBA to loop through a list of URLs and import the image source from each website. This is the code I have so far:

Public Sub Asins()
Dim IE As Object
Dim rng As Range, cell As Range
Dim URL As Range
Dim imgSrc
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
For Each URL In Range("A1:A3260")
.navigate URL.Value
While .busy Or .readyState <> 4: DoEvents: Wend
' This is where Im stuck. I need to print the image source of each URL next to its corresponding cell
' Set imgSrc = IE.document.getElementById("imageProduct")
' = imgSrc.getAttribute("src")

Next
End With
End Sub


Thanks for your help
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I suppose a better way to word my question would have been: How can I print data next to cell being looped?
Was a simple solution. This is what I did

Rich (BB code):
Public Sub Asins()
    Dim IE As Object
    Dim rng As Range, cell As Range
    Dim URL As Range
    Dim imgSrc
    Set IE = CreateObject("InternetExplorer.Application")
    With IE
        .Visible = True
        For Each URL In Range("A1:A3260")
            .navigate URL.Value
            While .busy Or .readyState <> 4: DoEvents: Wend
            Set imgSrc = IE.document.getElementById("imageProduct")
            URL.Range("B" & URL.Row) = imgSrc.getAttribute("src")
 
Upvote 0
Change the URL.Range... line to:
Code:
url.Offset(, 1).Value = imgSrc.getAttribute("src")

'Or

url(, 2).Value = imgSrc.getAttribute("src")
For this type of problem it can be helpful to use the Address property to determine exactly which cell or cells a Range reference is referring to:
Code:
            Debug.Print url.Range("B" & url.Row).Address, url.Offset(, 1).Address
 
Upvote 0

Forum statistics

Threads
1,215,218
Messages
6,123,676
Members
449,116
Latest member
HypnoFant

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top