Lookup customer name on IE and return address using VBA

TG2812

Board Regular
Joined
Apr 15, 2015
Messages
173
Hi,

I have a list of business names in Excel starting in cell A2 going down to A3, A4 etc. The record-set is pretty large as it contains over 100,000 rows. What I need to do is to retrieve the address for these business using IE and return the corresponding address in cell B2, B3 etc..

I'm pretty new in the coding world and was wondering if there is any VBA code you may think of I could use to perform this task automatically.

Thank you in advance for your valuable help.
 

TG2812

Board Regular
Joined
Apr 15, 2015
Messages
173
Hi,

I found a code that looks similar to what I'm attempting to do. I acquired a google API key, however, it keeps on returning the same address in column 15. I feel I'm close to the end result but I would need your help to further understand what is wrong in the below code.

Code:
Sub myTest()
    Dim xhrRequest As XMLHTTP60
    Dim domDoc As DOMDocument60
    Dim domDoc2 As DOMDocument60
    Dim placeID As String
    Dim query As String
    Dim nodes As IXMLDOMNodeList
    Dim node As IXMLDOMNode


    Dim rng As Range, cell As Range


    Set rng = Range("L2:L100")


    For Each cell In rng
On Error Resume Next


    query = cell.Value


    Dim googleKey As String
    googleKey =


    Set xhrRequest = New XMLHTTP60


    xhrRequest.Open "GET", "https://maps.googleapis.com/maps/api/place/textsearch/xml?" & _
        "query=" & query & "&key=" & googleKey, False
    xhrRequest.send


    Set domDoc = New DOMDocument60
    domDoc.LoadXML xhrRequest.responseText
    
    placeID = domDoc.SelectSingleNode("//result/place_id").Text


    Set domDoc = Nothing
    Set xhrRequest = Nothing


    Set xhrRequest = New XMLHTTP60
    xhrRequest.Open "GET", "https://maps.googleapis.com/maps/api/place/details/xml?placeid=" & placeID & _
    "&key=" & googleKey, False
    xhrRequest.send


    Set domDoc = New DOMDocument60
    domDoc.LoadXML xhrRequest.responseText


    Dim output As String
    Dim s As String


    Set nodes = domDoc.SelectNodes("//result/address_component/type")
    For Each node In nodes
        s = node.Text
        If s = "street_number" Then
            cell.Offset(0, 1).Value = "Address: " & node.ParentNode.FirstChild.Text
        End If


        If s = "postal_code" Then
            cell.Offset(0, 2).Value = "Postal Code: " & node.ParentNode.FirstChild.Text
        End If
    Next node
    
    Cells(cell.Row, 15) = domDoc.SelectSingleNode("//result/formatted_address").Text & output
    
    Next cell


End Sub
 
Last edited:

Forum statistics

Threads
1,081,969
Messages
5,362,477
Members
400,676
Latest member
BiochemBoi95

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top