HTML/VBA下拉菜单 [英] HTML / VBA Dropdown Menu
问题描述
我对VBA和HTML例程有一点问题.我必须从链接
事件处理程序:
选项显式公开子测试()作为InternetExplorer变暗,作为对象evt设置ie = New InternetExplorer与即.Visible = True.Navigate2"https://www.betexplorer.com/next/soccer/"而.Busy或.readyState<>4:DoEvents:Wend.document.querySelector(#nr-all [value ='2']").Selected = True设置evt = .document.createEvent("HTMLEvents")evt.initEvent"change",True,False.document.querySelector(#nr-all select").dispatchEvent evt停止'<以后删除我.放弃结束于结束子
I have a little problem with a VBA and HTML routine. I have to select from the link https://www.betexplorer.com/next/soccer/ the "Sort by:" drop-down menu and select the "Leagues" item. I can't do this via the VBA.
This is the code that I wrote
Sub Scarica()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLDoc1 As MSHTML.HTMLDocument
Dim Dropdowns As MSHTML.IHTMLElement
Dim post As MSHTML.IHTMLElement
Dim Elem As MSHTML.IHTMLElement
Application.StatusBar = "Download Elenco Campionati odierni in corso..."
Application.ScreenUpdating = False
Application.Calculation = xlManual
IE.Visible = True
IE.navigate "https://www.betexplorer.com/next/soccer/"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
'==================================================
' THIS IS THE PART THAT I CAN'T WRITE
'==================================================
Set HTMLDoc = IE.document
Set post = HTMLDoc.getElementById("wrap-header__list__item.semilong")
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
'==================================================
'==================================================
This is my first message and I'm not able to insert the HTML code of the website.
You can isolate the correct dropdown item for selection by combining the id of the parent select
with the attribute = value for the value
attribute of the appropriate child option
tag. The parent select
is expecting an onchange
event which you need to attach and dispatch.
Parent div
by id
and child option
by value
:
Event handler:
Option Explicit
Public Sub test()
Dim ie As InternetExplorer, evt As Object
Set ie = New InternetExplorer
With ie
.Visible = True
.Navigate2 "https://www.betexplorer.com/next/soccer/"
While .Busy Or .readyState <> 4: DoEvents: Wend
.document.querySelector("#nr-all [value='2']").Selected = True
Set evt = .document.createEvent("HTMLEvents")
evt.initEvent "change", True, False
.document.querySelector("#nr-all select").dispatchEvent evt
Stop '< delete me later
.Quit
End With
End Sub
这篇关于HTML/VBA下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!