+ Reply to Thread
Results 1 to 8 of 8

API Json to Excel Macro

Hybrid View

ermengard API Json to Excel Macro 09-30-2014, 08:49 AM
Kyle123 Re: API Json to Excel Macro 09-30-2014, 09:34 AM
ermengard Re: API Json to Excel Macro 09-30-2014, 08:20 PM
ermengard Re: API Json to Excel Macro 10-01-2014, 09:06 PM
Kyle123 Re: API Json to Excel Macro 10-02-2014, 02:15 AM
ermengard Re: API Json to Excel Macro 10-07-2014, 02:47 AM
Kyle123 Re: API Json to Excel Macro 10-07-2014, 04:14 AM
ermengard Re: API Json to Excel Macro 10-09-2014, 05:33 AM
  1. #1
    Registered User
    Join Date
    10-02-2012
    Location
    Philippines
    MS-Off Ver
    Excel 2003
    Posts
    29

    API Json to Excel Macro

    I am trying to import the following api json in excel table.
    http://api.manilainvestor.com/v1/stocks/hdata/dnl
    Can anyone help me develop the code for the macro.

    Data must be separated in these coloumns.

    Date | High | Low | Open | Close | Volume


    Thank you.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: API Json to Excel Macro

    This will dump the data in the first sheet, starting at A1

    Public Sub getData()
    
        Dim JSONObject As Object
        Dim scriptControl As Object
        Dim JS As Object
        Dim x As Long: x = 1
    
        Set scriptControl = CreateObject("MSScriptControl.ScriptControl")
        scriptControl.Language = "JScript"
        
        With CreateObject("MSXML2.XMLHTTP")
            .Open "GET", "http://api.manilainvestor.com/v1/stocks/hdata/dnl", False
            .send
            Set JSONObject = scriptControl.Eval("(" + .responsetext + ")")
            .abort
            For Each JS In JSONObject
                Sheets(1).Cells(x, 1).Value = JS.Date / (CDbl(60) * CDbl(60) * CDbl(24)) + #1/1/1970#
                Sheets(1).Cells(x, 2).Value = JS.High
                Sheets(1).Cells(x, 3).Value = JS.Low
                Sheets(1).Cells(x, 4).Value = JS.Open
                Sheets(1).Cells(x, 5).Value = JS.Close
                Sheets(1).Cells(x, 6).Value = JS.Volume
                x = x + 1
            Next JS
        End With
    End Sub

  3. #3
    Registered User
    Join Date
    10-02-2012
    Location
    Philippines
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: API Json to Excel Macro

    Thanks Kyle. You're awesome!

  4. #4
    Registered User
    Join Date
    10-02-2012
    Location
    Philippines
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: API Json to Excel Macro

    Hi Kyle,

    I tried to use your code Excel 2010, I am receiving error message to this line:

    Set scriptControl = CreateObject("MSScriptControl.ScriptControl")

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: API Json to Excel Macro

    What's the error?

  6. #6
    Registered User
    Join Date
    10-02-2012
    Location
    Philippines
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: API Json to Excel Macro

    I am getting the error Run-time error '429' ActiveX component can't create object in the line
    Set scriptControl = CreateObject("MSScriptControl.ScriptControl")
    using Excel 2010 x64.

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: API Json to Excel Macro

    You should have said that earlier really, MSScript Control is 32-bit and will work on 32-bit versions of Excel (on both 32 and 64-bit windows), but not the 64-bit version.

    This will need a complete re-write, I'll have a look when I get chance.

  8. #8
    Registered User
    Join Date
    10-02-2012
    Location
    Philippines
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: API Json to Excel Macro

    Thanks Kyle.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Importing JSON/XML into Excel from Web service
    By starfish_001 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2016, 08:20 AM
  2. Json file from URL to Excel
    By KK33317 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-21-2014, 10:50 AM
  3. Json file from URL to Excel
    By KK33317 in forum Tips and Tutorials
    Replies: 0
    Last Post: 03-13-2014, 07:39 AM
  4. Import JSON Api to Excel
    By hockeyadc in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-13-2014, 01:42 PM
  5. Import JSON in Excel by macro
    By bmmerkx in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-28-2013, 09:39 AM

Tags for this Thread

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