There may be a better way to send an HTTP Request and get the XML response
from VBA. If so, please let me know...
Here is my code:
Private Sub TestXMLHTTP()
Dim strURL As String
Dim oReq As XMLHTTP
On Error GoTo ErrRoutine
strURL =
"http://local.yahooapis.com/MapsService/V1/geocode?appid=YahooDemo&street=701+First+Ave&city=Sunnyvale&state=CA"
MsgBox (strURL)
oReq.Open("GET", strURL, False)
oReq.Send
Debug.Print oReq.responseText
Set oReq = Nothing
MsgBox (oReq.responseText)
EndRoutine:
Exit Sub
ErrRoutine:
MsgBox Err.Number & " - " & Err.Description, _
vbOKOnly Or vbCritical, _
"TestXMLHTTP"
GoTo EndRoutine
End Sub
Thanks for your help!
Kevin
Call oReq.Open("GET", strURL, False)
or
oReq.Open "GET", strURL, False
You only use the parenthesis for a function call with a return value or when
using the Call keyword.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"Kevin07003" <Kevin...@discussions.microsoft.com> wrote in message
news:A9E1558A-46A7-452F...@microsoft.com...
Here is the working code that also parses the XML Response:
Private Sub TestXMLHTTP()
Dim strURL As String
Dim oReq As Object
Set oReq = CreateObject("MSXML2.XMLHTTP")
Dim oDOM As Object
Set oDOM = CreateObject("MSXML2.DOMDocument.3.0")
oDOM.async = "false"
Dim oNodeList As IXMLDOMNodeList
Dim strLat, strLon As String
On Error GoTo ErrRoutine
strURL =
"http://local.yahooapis.com/MapsService/V1/geocode?appid=YahooDemo&street=701+First+Ave&city=Sunnyvale&state=CA"
oReq.Open "GET", strURL, False
oReq.Send
oDOM.LoadXML (oReq.responseText)
Set oReq = Nothing
Set oNodeList = oDOM.getElementsByTagName("Latitude")
If oNodeList.Length = 0 Then
MsgBox ("Latitude not found!")
GoTo EndRoutine
End If
strLat = oNodeList.Item(0).Text
Set oNodeList = oDOM.getElementsByTagName("Longitude")
If oNodeList.Length = 0 Then
MsgBox ("Longitude not found!")
GoTo EndRoutine
End If
strLon = oNodeList.Item(0).Text
MsgBox ("Latitude: " & strLat & Chr$(13) & "Longitude :" & strLon)
EndRoutine:
Exit Sub
ErrRoutine:
MsgBox Err.Number & " - " & Err.Description, _
vbOKOnly Or vbCritical, _
"TestXMLHTTP"
GoTo EndRoutine
End Sub