Created
May 29, 2015 18:35
-
-
Save fuzzysteve/28cef236c66ff388b732 to your computer and use it in GitHub Desktop.
new load prices for excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub LoadPrices() | |
Dim oHttp As Object | |
Dim jsonText As String | |
Dim jsonObj As Dictionary | |
Dim jsonRows As Collection | |
Dim jsonRow As Dictionary | |
Dim costInex As Collection | |
Dim ws As Worksheet | |
Dim currentRow As Long | |
Dim startColumn As Long | |
Dim i As Long | |
Set oHttp = CreateObject("MSXML2.XMLHTTP") | |
If Err.Number <> 0 Then | |
Set oHttp = CreateObject("MSXML.XMLHTTPRequest") | |
MsgBox "Error 0 has occured while creating a MSXML.XMLHTTPRequest object" | |
End If | |
On Error GoTo 0 | |
If oHttp Is Nothing Then | |
MsgBox "For some reason I wasn't able to make a MSXML2.XMLHTTP object" | |
Exit Sub | |
End If | |
oHttp.Open "GET", "https://public-crest.eveonline.com/market/prices/", False | |
oHttp.Send | |
'Create a real JSON object | |
jsonText = oHttp.responseText | |
Set ws = Worksheets("PriceData") | |
'Parse it | |
Set jsonObj = JSON.parse(jsonText) | |
'Get the rows collection | |
Set jsonRows = jsonObj("items") | |
'Set the starting row where to put the values | |
currentRow = 1 | |
'First column where to put the values | |
startColumn = 1 'A | |
'Loop through all the values received | |
For Each jsonRow In jsonRows | |
currentRow = currentRow + 1 | |
ws.Cells(currentRow, startColumn).Value = jsonRow("type")("id") | |
ws.Cells(currentRow, 2).Value = jsonRow("adjustedPrice") | |
ws.Cells(currentRow, 3).Value = jsonRow("averagePrice") | |
Next jsonRow | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment