Problem with html tags still displayed in web query

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
It's because the HTML is missing table tags so that it can be inserted into another page. Try this:
Code:
Sub Golf()

    Dim URL As String
    Dim IE As Object
    Dim elements As Object
    Dim lines As Variant
    
    URL = "http://www.europeantour.com/europeantour/season=2010/tournamentid=2010005/stats/roundno=1/index.html"
    
    Set IE = CreateObject("InternetExplorer.Application")
    
    With IE
        .Visible = True
        .navigate URL
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        Set elements = .document.getElementsByTagName("HTML")
        .Quit
    End With
    
    lines = Split(elements(0).innerText, vbCrLf)
    
    With Worksheets("Sheet1")
        .Columns("A").ClearContents
        .Columns("A").NumberFormat = "@"        'Text format
        .Range("A1").Resize(UBound(lines) - LBound(lines) + 1, 1) = Application.WorksheetFunction.Transpose(lines)
    End With
        
End Sub
 
Upvote 0
Thanks for the code, john_w.

I'm not sure what to do with it, though. When I run this code, it opens the page that I want to web query in my browser, but does nothing in the Excel file. When I close the browser, I get: run-time error '-2147467259 (80004005)' Automation error Unspecified error.
 
Upvote 0
Try this version instead - in converting it to late binding I left a bug in. The code can go in a sheet module or a standard code module, it doesn't matter. Run the Golf macro and it should populate column A on Sheet1.
Code:
Sub Golf()

    Dim URL As String
    Dim IE As Object
    Dim elements As Object
    Dim lines As Variant
    
    URL = "http://www.europeantour.com/europeantour/season=2010/tournamentid=2010005/stats/roundno=1/index.html"
    
    Set IE = CreateObject("InternetExplorer.Application")
    
    With IE
        .Visible = True
        .navigate URL
        While .Busy Or .readyState <> 4: DoEvents: Wend
        Set elements = .document.getElementsByTagName("HTML")
        lines = Split(elements(0).innerText, vbCrLf)
        .Quit
    End With
    
    With Worksheets("Sheet1")
        .Columns("A").ClearContents             'Clear column A
        .Columns("A").NumberFormat = "@"        'Text format
        .Range("A1").Resize(UBound(lines) - LBound(lines) + 1, 1) = Application.WorksheetFunction.Transpose(lines)
    End With
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,787
Messages
6,126,900
Members
449,348
Latest member
Rdeane

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