Web API

Kentman

Active Member
Joined
Apr 26, 2010
Messages
260
I'd like to call a web api to geocode some addresses - does anyone know of VBA code or Excel workbook to do this?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
There's a simple api (http://tinygeocoder.com/create-api.php?q=) which takes an address or place as a parameter and pulls back coordinates. I'd like to be able to have a list of places and push them into the api and get the results back in a worksheet so, if I input "Leicester, uk" as the parameter at the URL I would get back the coordinates for Leicester.

I'm OK with VBA but don't know how to go about sending and getting information from the web.
 
Upvote 0
Make a long list of locations (1 per row) and run this code

Code:
Option Explicit

Sub GEO_Coder()

    Do While ActiveCell.Value <> ""
        With ActiveSheet.QueryTables.Add(Connection:= _
            "URL;http://tinygeocoder.com/create-api.php?q=""" & ActiveCell.Value & """", Destination:=Range(ActiveCell.Offset(0, 1).Address))
            .Name = "create-api.php?q="" & activecell.value & ""_1"
            .Refresh
        End With
        ActiveCell.Offset(1, 0).Select
    Loop

End Sub

Click on the first row before you run. It'll step through each cell (until an empty cell is reached) and will return the value from the site.
 
Upvote 0
DauntingGecko thanks very much that worked great except - there always has to be an except! The results are progressively moved 1 column over so if I have a list of 50 the 50th will be 50 columns to the right.

Could you alter code so that they are in the same column? Much appreciated.;)
 
Upvote 0
Code:
    Do While ActiveCell.Value <> ""
        With ActiveSheet.QueryTables.Add(Connection:= _
            "URL;http://tinygeocoder.com/create-api.php?q=""" & ActiveCell.Value & """", _
                     Destination:=Range(ActiveCell.Offset(0, 1).Address))
            .Name = "create-api.php?q="" & activecell.value"
            .RefreshStyle = xlOverwriteCells
            .Refresh
        End With
        ActiveCell.Offset(1, 0).Select
    Loop
 
Last edited:
Upvote 0
Indeed!

Could the result be put into a variable and the contents of the variable then placed into a cell?
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,786
Members
452,942
Latest member
VijayNewtoExcel

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