真的很感激,如果有人可以提供帮助。 代码部分总是遇到运行时错误 enter image description here HTML部分在图片中 enter image description here
感谢您的关注。
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
答案 0 :(得分:0)
它不是元素ID - 它是标记名称; Set EuroButton = HTMLDoc.getElementsByTagName("btn_eur")
然后当您需要订购它时:EuroButton(0).[command here]
答案 1 :(得分:0)
您选择器还不错。它确实具有该ID。问题是您需要适当的等待页面加载,然后才能尝试单击。请尝试以下。我还更新了.navigate2并删除了不必要的()。
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