Results 1 to 4 of 4

Importing JSON/XML into Excel from Web service

Threaded View

  1. #3
    Registered User
    Join Date
    07-03-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Importing JSON/XML into Excel from Web service

    I have looked at pulling data from web pages but not something using JSON that requires authentication

    https://celoxis.atlassian.net/wiki/p...ageId=39321957

    https://celoxis.atlassian.net/wiki/p...ageId=39321951


    Const URl As String = "http://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol=ICICIBANK"
    Sub xmlHttp()

    Dim xmlHttp As Object
    Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
    xmlHttp.Open "GET", URl & "&rnd=" & WorksheetFunction.RandBetween(1, 99), False
    xmlHttp.setRequestHeader "Content-Type", "text/xml"
    xmlHttp.send

    Dim html As MSHTML.HTMLDocument
    Set html = New MSHTML.HTMLDocument
    html.body.innerHTML = xmlHttp.ResponseText

    Dim divData As Object
    Set divData = html.getElementById("responseDiv")
    '?divData.innerHTML
    ' Here you will get a string which is a JSON data

    Dim strDiv As String, startVal As Long, endVal As Long
    strDiv = divData.innerHTML
    startVal = InStr(1, strDiv, "data", vbTextCompare)
    endVal = InStr(startVal, strDiv, "]", vbTextCompare)
    strDiv = "{" & Mid(strDiv, startVal - 1, (endVal - startVal) + 2) & "}"


    Dim JSON As New JSON

    Dim p As Object
    Set p = JSON.parse(strDiv)

    i = 1
    For Each item In p("data")(1)
    Cells(i, 1) = item
    Cells(i, 2) = p("data")(1)(item)
    i = i + 1
    Next

    End Sub
    Last edited by starfish_001; 08-08-2014 at 12:02 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Json file from URL to Excel
    By KK33317 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-21-2014, 10:50 AM
  2. Json file from URL to Excel
    By KK33317 in forum Tips and Tutorials
    Replies: 0
    Last Post: 03-13-2014, 07:39 AM
  3. Replies: 0
    Last Post: 11-01-2012, 06:23 AM
  4. Importing JSON Data into Excel
    By Kyle123 in forum Excel Tips
    Replies: 1
    Last Post: 07-25-2012, 08:47 AM
  5. Importing XML through .NET Web Service with VBA
    By brazilnut in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-07-2005, 06:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1