October 2011 - Posts

Using Excel to Geocode with Bing Maps Web Services
Tuesday, October 04, 2011 11:00 AM

A lot of folks have to geocode data that they get from various folks in their organization, and it often makes its way in to Excel.  Of course, you can batch geocode using Bing Maps Services, but in some scenarios it is a lot more convenient or reasonable to use Excel.

Wouldn’t it be handy if there was an Excel function like =GEOCODE(<Some Address>)?

Well, here it is.

This uses the Bing Maps REST services and synchronous VBA and XML.  This is similar to asynchronous JavaScript and XML (AJAX) but in this case it would be SVAX.

This code is provided without warranty, etc.

You will need a Bing Maps key (See: Getting a Bing Maps Key), Excel, and an internet connection.

Option 1:  Create your own module

  1. Expose the Developer tools (See: Show the Developer Tab)
  2. Click the Visual Basic button
  3. Insert a Module
  4. Paste in this code and modify as you see fit:

Option Explicit

Function GeocodeAddress(address As String, BingMapsKey As String) As String

    Dim oHttpReq As MSXML2.XMLHTTP

    Set oHttpReq = New MSXML2.XMLHTTP

    oHttpReq.Open "get", "https://dev.virtualearth.net/REST/v1/Locations?q=" & address & "&o=xml&key=" & BingMapsKey, "false"

    oHttpReq.send

    If oHttpReq.readyState = 4 Then

        GeocodeAddress = oHttpReq.responseXML.SelectNodes("//Point/Latitude").Item(0).Text & "," & oHttpReq.responseXML.SelectNodes("//Point/Longitude").Item(0).Text

    End If

End Function

Function DriveDistance(From As String, Dest As String, BingMapsKey As String) As String

    Dim oHttpReq As MSXML2.XMLHTTP

    Set oHttpReq = New MSXML2.XMLHTTP

    oHttpReq.Open "get", "https://dev.virtualearth.net/REST/V1/Routes/Driving?o=xml&wp.0=" & From & "&wp.1=" & Dest & "&avoid=minimizeTolls&key=" & BingMapsKey, "false"

    oHttpReq.send

    If oHttpReq.readyState = 4 Then

        DriveDistance = oHttpReq.responseXML.SelectNodes("//TravelDistance").Item(0).Text

    End If

End Function

Function GetStateCountryFromPoint(Lat As String, Lon As String, BingMapsKey As String) As String

    Dim oHttpReq As MSXML2.XMLHTTP

    Set oHttpReq = New MSXML2.XMLHTTP

    oHttpReq.Open "get", "https://dev.virtualearth.net/REST/v1/Locations/" & Lat & "," & Lon & "?o=xml&key=" & BingMapsKey, "false"

    oHttpReq.send

    If oHttpReq.readyState = 4 Then

        If oHttpReq.responseXML.SelectNodes("//Address/AdminDistrict").Length > 0 Then

            GetStateCountryFromPoint = oHttpReq.responseXML.SelectNodes("//Address/AdminDistrict").Item(0).Text & ", " & oHttpReq.responseXML.SelectNodes("//Address/CountryRegion").Item(0).Text

        Else

            GetStateCountryFromPoint = "No Country"

        End If

    End If

End Function

 

Now you can use cell references or addresses to geocode your addresses or find the distance between two locations.

E.g. =GeocodeAddress(“San Antonio, TX”, BingMapsKey)

clip_image002

 

Option 2:   Add this file to your Add-ins directory.

 

(See: Office.com: Add or remove add-ins )

This also includes several other geocoding functions.

by wkriebel | with no comments
Filed under: , ,
Automatically Update Charts, Graphs, and Reports in PowerPoint
Tuesday, October 04, 2011 10:14 AM

Here is a neat trick for getting graphs in PowerPoint to automatically update from SQL Reporting Services.

Prerequisites:

  • Word
  • PowerPoint
  • SQL Reporting Services
  1. Go directly to the report server, not the SharePoint integrated mode. Have it output to HTML,
  2. insert it into a field in Word, then
  3. embed that word document in a PowerPoint slide.

http://ReportServerMachine/ReportServer?http://LocationOfReport/Shared%20Documents/DailyReport.rdl&rs:Command=Render&rs:Format=HTML4.0&rc:Toolbar=False

Alternatively, you can render it as an image:
http://ReportServerMachine/ReportServer?http://LocationOfReport/Shared%20Documents/DailyReport.rdl&rs:Command=Render&rs:Format=Image&rc:Toolbar=False&rc:OutputFormat=PNG

The reason for this is that the SharePoint integration puts in a bunch of AJAX that confuses Word. The report server can produce pure HTML with no Javascript.

 

Thanks:  Shashank Pawar, his post has some screenshots.

More Posts