0
下面的宏在IE9中工作,但是当使用IE11时它停止在Do While
语句上。此外,Set HTMLDoc = ie.document
也不会出于同样的原因。READYSTATE永远不会获得完成状态
请注意,该网站将无法正常工作,因为它仅限于某些用户。
Option Explicit
Sub GetHTMLDocument()
Dim ie As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim htmlbuttons As MSHTML.IHTMLElementCollection
Dim htmlbutton As MSHTML.IHTMLElement
ie.Visible = True
ie.navigate "siiprodsrs01.db.sma"
Do While ie.readyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = ie.document
Set HTMLInput = HTMLDoc.getElementById("what")
HTMLInput.Value = "12345"
Set htmlbuttons = HTMLDoc.getElementsByTagName("button")
For Each htmlbutton In htmlbuttons
Debug.Print htmlbutton.className, htmlbutton.tagName, htmlbutton.ID, htmlbutton.innerText
Next htmlbutton
htmlbuttons(0).Click
End Sub
不错的一个!我如何使它与我想要访问不同域中的元素的多个选项卡一起工作 - 只需向IF块添加另一个案例? – PatricK
谢谢你的回复。该宏没有运行,因为声明了'Dim WithEvents ie InternetExplorer'。即使我已经在引用中勾选了Microsoft Internet控件,但它仍然以红色显示。感谢您的时间 – Dawood
@达伍德,您是否引用了Microsoft Internet Controls? – exSnake