1

Really appreciate if anyone can help. The part of code always run into Run - time Error:

enter image description here

The HTML part is in the picture:

enter image description here

Thanks for attention.

Sub HTML_Table_To_Excel()
    Dim objIE As Object
    Set objIE = CreateObject("InternetExplorer.application")
    With objIE
        .Visible = True
        .navigate ("http://www.global-rates.com/interest-rates/libor/libor.aspx")
    End With
    While objIE.Busy
    Wend
    
    Dim HTMLDoc As Object
    Set HTMLDoc = objIE.document
    
    Dim EuroButton As Object
    Set EuroButton = HTMLDoc.getElementById("btn_eur")
    
    objIE.Quit
    Set objIE = Nothing
......
End Sub
Barbora
  • 921
  • 1
  • 6
  • 11
AntiqueWhale
  • 171
  • 1
  • 4
  • Which line does it fail on? If you put a break on that line and wait a couple of seconds before continuing execution, does it still fail? – Tim Williams Feb 13 '17 at 19:55
  • @TimWilliams Set EuroButton = ..... This line fails. And thanks,Tim, if I put a break point there, and wait for a while, the sub doesn't fail. – AntiqueWhale Feb 13 '17 at 21:59
  • I think you need to extend your `While IE.Busy` check: see - http://stackoverflow.com/questions/19334880/ie-busy-not-working-well-vba – Tim Williams Feb 13 '17 at 22:55

2 Answers2

0

It's not an element ID - it's a tag name; Set EuroButton = HTMLDoc.getElementsByTagName("btn_eur") then when you need to order it: EuroButton(0).[command here]

Jeremy
  • 1,337
  • 3
  • 12
  • 26
0

You were just fine with your selector. It does have that id. The problem is you need a proper wait for page load before attempting to click. Try the below. I have also updated to .navigate2 and removed the unnecessary ().

Option Explicit
Public Sub HtmlTableToExcel()
    Dim objIE As Object, HTMLDoc As Object, euroButton As Object
    Set objIE = CreateObject("InternetExplorer.application")
    With objIE
        .Visible = True
        .Navigate2 "http://www.global-rates.com/interest-rates/libor/libor.aspx"

        While .Busy Or .readyState < 4: DoEvents: Wend

        Set HTMLDoc = .document
        Set euroButton = HTMLDoc.getElementById("btn_eur")
        euroButton.Click
        While .Busy Or .readyState < 4: DoEvents: Wend
         Stop '<==delete me later
        '-----
        '.Quit
    End With
End Sub
QHarr
  • 83,427
  • 12
  • 54
  • 101