Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using MSXML2.XMLHTTP in VBA?

10,020 views
Skip to first unread message

Kevin07003

unread,
Mar 16, 2008, 3:54:00 PM3/16/08
to
Hello,
I'm trying to use the XMLHTTP object from the MSXML2 library in Outlook VBA.
I get a compile error "Expected: =" on the "oReq.Open" command.

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

Ken Slovak - [MVP - Outlook]

unread,
Mar 17, 2008, 8:31:52 AM3/17/08
to
I have no idea what this has to do with Outlook programming, but in VBA code
try either of these two lines:

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...

Kevin07003

unread,
Mar 18, 2008, 10:25:01 PM3/18/08
to
Thanks - that was part of the problem. I haven't used VBA since 1998 or so!

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

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

0 new messages