Web Query - Select Table not being captured

kamster2

New Member
Joined
Jun 29, 2011
Messages
4
Hi,

Anchoring upon CodyMaster's post about a year and a half ago:
http://www.mrexcel.com/forum/showthread.php?t=444596

I'm going through CME Group in excel and trying to pull the block trades data from the address below:

http://www.cmegroup.com/clearing/tr...&exchanges=XCBT,XCME,XCEC,XNYM&assetclass=1,6

But when I launch the query using standard Excel 2007 procedure, it does not pull the table data--I got everything else but that.
According to Tom Schreiner, the table is loaded dynamically after the page is loaded. Moreover, to actually select the data, I will need to use the "GET information" via a software called "IEWatch" (http://www.iewatch.com/) which is very expensive in my regard for a one-time usage.

I wonder if anyone can help me to pull the block trades into the excel. Thanks a lot!

-Jason
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try the following (put the code in a standard module). The code uses early binding, therefore the VBA project requires references to the MS HTML Object Library and XML v6.0. Set these in Tools - References in the VB editor.
Code:
'References Microsoft HTML Object Library and Microsoft XML v6.0

Option Explicit

Sub Test()

    Dim dataStartCell As Range
    
    Set dataStartCell = ActiveSheet.Range("A1")
    dataStartCell.Parent.Cells.ClearContents
    
    Get_Block_Trades Now, dataStartCell
    
End Sub


Sub Get_Block_Trades(tradeDate As Date, destinationCell As Range)

    Dim milliseconds As String
    Dim URL As String
    Dim XMLHttp As MSXML2.XMLHttp
    Dim HTMLDoc As HTMLDocument
    Dim table As HTMLTable
    Dim tableRow As HTMLTableRow
    Dim tableCell As HTMLTableCell
    
    milliseconds = DateDiff("s", "01-Jan-1970", Now) * 1000         'Equivalent to Javascript getTime() function
    URL = "http://www.cmegroup.com/CmeWS/mvc/xsltTransformer.do" & _
        "?xlstDoc=/XSLT/md/blocks-records.xsl&url=/da/BlockTradeQuotes/V1/Block/BlockTrades" & _
        "?exchange=XCBT,XCME,XCEC,XNYM&foi=FUT,OPT,SPD&assetClassId=1,6" & _
        "&tradeDate=" & Format(tradeDate, "mmddyyyy") & "&sortCol=time&sortBy=desc&_=" & milliseconds
    
    Set XMLHttp = New MSXML2.XMLHttp        'For late binding use CreateObject("Microsoft.XMLHTTP")
    XMLHttp.Open "GET", URL, False
    XMLHttp.send
        
    'Put response in a HTMLDocument for parsing
    
    Set HTMLDoc = New HTMLDocument
    HTMLDoc.body.innerHTML = XMLHttp.responseText
    
    'Loop through rows and columns in first table, writing the data to Excel cells
    
    Set table = HTMLDoc.getElementsByTagName("TABLE")(0)
    For Each tableRow In table.Rows
        For Each tableCell In tableRow.Cells
            destinationCell.Offset(tableRow.RowIndex, tableCell.cellIndex).Value = tableCell.innerText
        Next
    Next
    
End Sub
 
Upvote 0
To add to the above macro, is it possible to add a macro that would automatically send emails if only new data is pulled in after refreshing?

Thanks in advance.
 
Upvote 0

Forum statistics

Threads
1,223,714
Messages
6,174,044
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top