Ok, so I'm trying to make a complex geocoding script in VBA. I have written the following code and for some reason it returns an error ("Run-time error 91: Object variable or With block variable not set"). An example of a link that I use can be: "https://maps.googleapis.com/maps/api/geocode/xml?address=1+Infinite+Loop,+Cupertino,+Santa+Clara,+California+95014&sensor=false".
Sub readXML(link As String)
Dim odc As DOMDocument
Dim lat As IXMLDOMElement
Dim lng As IXMLDOMElement
Set odc = New MSXML2.DOMDocument
odc.async = False
odc.Load (link)
lat = odc.SelectSingleNode("GeocodeResponse/result/geometry[location_type='ROOFTOP']/location/lat").Text
lng = odc.SelectSingleNode("GeocodeResponse/result/geometry[location_type='ROOFTOP']/location/lng").Text
Debug.Print lat & "; " & lng
End Sub
Can anyone tell me what I'm doing wrong?