How can I pull data from a specific table with VBA on a webpage with lots of tables.

borski88

Board Regular
Joined
Jul 3, 2015
Messages
71
Here is my current code:

Code:
[FONT=courier new]Sub Pull_URL_Data()

                Dim myURL As String: 'URL String  
                 myURL = "https://www.website.com
                Call pullDataSingleURL(myURL, Sheets("Sheet1"))
                   
End Sub

Function pullDataSingleURL(URL As String, ws As Worksheet)
    'Add: (menu) Tools/References/'Microsoft XML V6.0' & 'Microsoft Forms 2.0 Object Library'
    'Dim httpRequest As XMLHTTP      'XML V6.0
    Dim httpRequest As MSXML2.XMLHTTP60      'MSXML2.DOMDocument
    Dim DataObj As New MSForms.DataObject   'Forms 2.0
    
    'Set httpRequest = New XMLHTTP
    Set httpRequest = CreateObject("MSXML2.XMLHTTP.6.0")
    httpRequest.Open "GET", URL, False
    httpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    httpRequest.send ""
    
    DataObj.SetText httpRequest.responseText
    DataObj.PutInClipboard
    
    DoEvents
    
    With ws
        .Activate
        .Cells.Clear
        .Cells(1, 1).Select
        .PasteSpecial Format:="Text", link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
    End With
End Function[/FONT]

The problem is the page I am trying to pull data from has a ton of tables on it.

In the source code I found the table id:

Code:
table id="function-4300002411" class="sortable result-table align-left"


Is there any way to use this info to only pull that specific data?
 
Last edited:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Have you tried using a simple Web Query? At the top of Excel, go to DATA > Get External Data > From WEB
 
Upvote 0
I get an error when trying to pull data from that site using the the Simple Web Query method.

The above method I posted seems to get around the error but I can't specify the table that I need.
 
Upvote 0
I get an error when trying to pull data from that site using the the Simple Web Query method.

The above method I posted seems to get around the error but I can't specify the table that I need.

what is the website and table?
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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