Excel VBA to connect to API
Hello all,
I am trying to use Excel to do an API request.
I was able to recreate the code from a popular youtube video, "Excel VBA Using A Web Service with XMLHTTP - Weather Forecast".
I am trying to access https://flightaware.com/commercial/flightxml but I can't seem to get the code.
I am new to VBA. All help is appreciated!
Regards,
Marc
Hello all,
I am trying to use Excel to do an API request.
I was able to recreate the code from a popular youtube video, "Excel VBA Using A Web Service with XMLHTTP - Weather Forecast".
I am trying to access https://flightaware.com/commercial/flightxml but I can't seem to get the code.
I am new to VBA. All help is appreciated!
Regards,
Marc
Code:
Option Explicit
Sub GetFlighInfo()
Dim W As Worksheet: Set W = ActiveSheet
Dim XMLReq As New MSXML2.XMLHTTP60
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim myInfo As String
'assigns my info
myInfo = "http://myApi@flightxml.flightaware.com/json/FlightXML2/"
'-----------
'how do I request dal82 flight status (Delta Airlines flight 82)
'-----------
'request
XMLReq.Open "GET", myInfo, False
XMLReq.send
If XMLReq.Status <> 200 Then
MsgBox "ERROR"
End If
'response
HTMLDoc.body.innerHTML = XMLReq.responseText
W.Cells(5, 5).Value = HTMLDoc.body.innerHTML
End Sub