Web Services In Excel for Mac

warren 1 Reputation point
2021-02-17T16:49:18.877+00:00

Hello All,

I have a VBA Excel ad-in that works on windows, but not on Mac because the web libraries don't exist.

I have removed my key, as this charges me money every time it's run, but otherwise this code executes correctly on Windows:

Function G_DISTANCE(Origin As String, Destination As String) As Double
Dim myRequest As XMLHTTP60
Dim myDomDoc As DOMDocument60
Dim distanceNode As IXMLDOMNode
    G_DISTANCE = 0
    On Error GoTo exitRoute
    Origin = Replace(Origin, " ", "%20")
    Destination = Replace(Destination, " ", "%20")
    Set myRequest = New XMLHTTP60
    myRequest.Open "GET", "https://maps.googleapis.com/maps/api/directions/xml?units=imperial&origin=" _
        & Origin & "&destination=" & Destination & "&key=", False
    myRequest.send
    Set myDomDoc = New DOMDocument60
    myDomDoc.LoadXML myRequest.responseText
    Set distanceNode = myDomDoc.SelectSingleNode("//leg/distance/value")
    If Not distanceNode Is Nothing Then G_DISTANCE = distanceNode.Text / 1609
exitRoute:
    Set distanceNode = Nothing
    Set myDomDoc = Nothing
    Set myRequest = Nothing
End Function

Sub GetMapsDistances()
    Dim xhrRequest As XMLHTTP60
    Dim domDoc As DOMDocument60
    Dim ixnlDistanceNodes As IXMLDOMNodeList
    Dim ixnNode As IXMLDOMNode
    Dim TtlDist As Long

    ' Donated to MrExcel users by diddi
    ' Read the data from the website

    Set xhrRequest = New XMLHTTP60
    xhrRequest.Open "GET", "http://maps.googleapis.com/maps/api/directions/xml?origin=" & Sheet2.Range("A4").Value & "&destination=" & Sheet2.Range("A6").Value & "&sensor=false", False
    'xhrRequest.Open "GET", "http://maps.googleapis.com/maps/api/directions/xml?origin=" & ComboBox1.Value & "&destination=" & ComboBox2.Value & "&sensor=false", False
    xhrRequest.send

    Set domDoc = New DOMDocument60
    domDoc.LoadXML xhrRequest.responseText

    Set ixnlDistanceNodes = domDoc.SelectNodes("//step/distance/value")

    '  Total up the distance from node to node
    TtlDist = 0
    For Each ixnNode In ixnlDistanceNodes
        TtlDist = TtlDist + Val(ixnNode.Text)
    Next ixnNode

    'Label1.Caption = "One way distance is about " & Int(TtlDist / 1000) & "km"
    'Label2.Caption = "Return trip is about " & Int(TtlDist * 2 / 1000) & "km"
    'Sheet2.Range("c8") = "One way distance is about " & Int(TtlDist / 1000) & " km"

    Set ixnNode = Nothing
    Set ixnlDistanceNodes = Nothing
    Set domDoc = Nothing
    Set xhrRequest = Nothing
End Sub

Any ideas on making this Mac friendly?

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,896 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.