Vba 将Web表数据导入excel
我想通过vba将每月数据从“”输入excel 以下是时间框架下拉菜单的源代码:-Vba 将Web表数据导入excel,vba,Vba,我想通过vba将每月数据从“”输入excel 以下是时间框架下拉菜单的源代码:- <select id="data_interval" class="newInput selectBox float_lang_base_1"> <option value="Daily" selected="">Daily</option> <option value="Weekly">Weekly</option>
<select id="data_interval" class="newInput selectBox float_lang_base_1">
<option value="Daily" selected="">Daily</option>
<option value="Weekly">Weekly</option>
<option value="Monthly">Monthly</option>
</select>enter code here
2是每月索引号,它可以从下拉菜单中选择每月索引,但表格不会从每周更新到每月,我也想将此数据输入excel中。试试这样,它可能适合您,具体取决于您的Internet Explorer
Option Explicit
Sub GetData()
Dim IE As Object
Dim Links As Object
Dim evt As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate ("https://uk.investing.com/indices/us-spx-500-historical-data")
IE.Visible = True
Do
DoEvents
Loop Until IE.readyState = 4
Set Links = IE.document.GetElementById("data_interval")
Set evt = IE.document.createevent("htmlevents")
evt.initevent "change", True, False
Links.Focus
Links.SelectedIndex = 2
Links.FireEvent ("onChange")
Links.dispatchevent evt
End Sub
感谢您正确地触发了事件。感谢老兄,它在以前版本的IE上工作过,但不是当前版本的IE。非常好的方法+1
Sub GetData()
Dim IE As Object
Dim Links
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate ("https://uk.investing.com/indices/us-spx-500-historical-data")
IE.Visible = True
Do
DoEvents
Loop Until IE.readyState = 4
Set Links = IE.document.getElementById("data_interval")
Links.selectedIndex = 2
End Sub
Option Explicit
Sub GetData()
Dim IE As Object
Dim Links As Object
Dim evt As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate ("https://uk.investing.com/indices/us-spx-500-historical-data")
IE.Visible = True
Do
DoEvents
Loop Until IE.readyState = 4
Set Links = IE.document.GetElementById("data_interval")
Set evt = IE.document.createevent("htmlevents")
evt.initevent "change", True, False
Links.Focus
Links.SelectedIndex = 2
Links.FireEvent ("onChange")
Links.dispatchevent evt
End Sub