Importing Web Data From Javascript Table

midsession

Board Regular
Joined
Oct 12, 2006
Messages
70
I have been using a web query within a macro to read data from web pages. I now need to adapt this to read data displayed in a table but contained in a .js file. Using a standard web query results in the retrieval of an empty data set. Is there a way to import what I want in VBA?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Is there not enough detail here?
I can see the table I need in 'View Source' - it's displayed as
HTML:
</STYLE>
<SCRIPT LANGUAGE="JavaScript" SRC="http://www.website.com/main.js"></SCRIPT>

I could find the table name by parsing innerHTML but what do I do with it then?
 
Last edited:
Upvote 0
It is difficult to help you without the url because web pages are so unique. Can you provide the URL? Can you PM it too me? If not, can you save the source HTML of each step in your navigation, open it in notepad, do a find replace of confidential data, and then post the HTML source here?
 
Upvote 0
<a href="http://home.fuse.net/tstom/0630081032.1609309.xls"><img src="http://home.fuse.net/tstom/zip.gif"width="48"height="48"border="0"></a> <a href="http://home.fuse.net/tstom/0630081032.1609309.xls">0630081032.1609309.xls</a>

I use the WebBrowser control as opposed to ie.exe because of issues with tabbed browsing.

Easy way without all of the custom parsing...

Add UserForm1 containing WebBrowser1.
Placement does not matter as you will never see the form.
There is no code in UserForm1.

Midsession. Replace "http://www.DOMAIN.com/data.asp" with the correct URL to the page, not the jScript URL. The WebBrowser control will load and render it for you...

In a standard or public class module:
Code:
Option Explicit
 
Private WithEvents wb As WebBrowser
Private uf As New UserForm1
 
Sub GetSomeData()
    Set wb = uf.WebBrowser1
    wb.RegisterAsBrowser = True
    wb.Navigate "http://www.DOMAIN.com/data.asp"
End Sub
 
Private Sub wb_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Dim TempFileName As String
 
    TempFileName = ThisWorkbook.Path & Application.PathSeparator & Timer & ".html"
    Open TempFileName For Output As #1
        Print #1, wb.Document.All(0).outerHTML
    Close #1
 
    With ActiveSheet.QueryTables.Add("URL;file:///" & TempFileName, Range("A1"))
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = "15,19"
        .Refresh BackgroundQuery:=False
        .Delete
    End With
 
    On Error Resume Next
    Kill TempFileName
    Set wb = Nothing
    Unload uf
    Set uf = Nothing
End Sub
 
Last edited by a moderator:
Upvote 0
I get an IE Script error running this - Object Expected, line 190, char 1
Then you get 'do you want to continue running scripts on this page?' - regardless of your answer the proc runs to completion.

Looks like it gives me what I needed as well, so thanks a million. A timely and elegant solution that I would never have found on my own

midsession
 
Upvote 0
Hi all,

I know it's an old subject, but I'm struggling with similar issue:

I want to capture some web data that is stored under address:

http://datatable/guiui/WFMonitor/WFMonitor.asp (I slightly changed it as it's an internal URL)

The thing is that to get what I want, I have to click on row name to see the details of it, but the URL doesn't change.


I tried the Tom Schreiner's solution, but I might not be that fluent with VBA: I created a UserForm with WebBrowser and also created a Class Module with the above code, but how do I make it all work?
 
Upvote 0

Forum statistics

Threads
1,223,106
Messages
6,170,129
Members
452,304
Latest member
Thelingly95

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