I'm trying to use the following code to get the distance from zip to zip in excel. However, when I try to execute the function it would give me the compile error: User-defined type not defined. I researched online and I found out that I need to set the reference to Microsoft XML v6.0. The issue is that when I go to Tools/Reference it would give me the error: Error accessing the system registry. Do anyone has any idea of how to solve this. Thank you in advance.
Option Explicit
Function GetDistance(sPCode As String, ePcode As String) As Double
Dim t As String
Dim re As XMLHTTP
t = "https://maps.googleapis.com/maps/api/js?key=APIKEY" & sPCode & "&wp.1=" & ePcode & "&avoid=minimizeTolls&du=mi&key=YOUR_MS_KEY"
Set re = New XMLHTTP
re.Open "get", t, False
re.send
Do
DoEvents
Loop Until re.readyState = 4
With re
s = Split(.responseText, "<TravelDistance>")
End With
GetDistance = Val(s(1))
End Function