1.参照项目
Microsoft Internet Controls
Microsoft HTML Object
2.sample
Sub GetIEItem()
Dim objIE As InternetExplorer
Set objIE = CreateObject("Internetexplorer.Application")
objIE.Visible = True
Dim url As String
url = "https://www.baidu.com/"
objIE.Navigate url, "JDK1.8"
Application.Wait Now() + TimeValue("00:00:03")
Dim htmlDoc As HTMLDocument
Set htmlDoc = objIE.Document
htmlDoc.getElementById("kw").value = "JDK1.8"
htmlDoc.getElementById("su").Click
Application.Wait Now() + TimeValue("00:00:03")
' Dim element As IHTMLElement
'
' For Each element In htmlDoc.getElementsByTagName("h1")
' Debug.Print element.innerText
' Next element
'
' Dim tr As HTMLTableRow
' For Each tr In htmlDoc.getElementsByTagName("tbody")(0).getElementsByTagName("tr")
'
' Next tr
End Sub
Dim objIE As InternetExplorer
Set objIE = CreateObject("Internetexplorer.Application")
objIE.Visible = True
Dim url As String
url = "https://www.baidu.com/"
objIE.Navigate url, "JDK1.8"
Application.Wait Now() + TimeValue("00:00:03")
Dim htmlDoc As HTMLDocument
Set htmlDoc = objIE.Document
htmlDoc.getElementById("kw").value = "JDK1.8"
htmlDoc.getElementById("su").Click
Application.Wait Now() + TimeValue("00:00:03")
' Dim element As IHTMLElement
'
' For Each element In htmlDoc.getElementsByTagName("h1")
' Debug.Print element.innerText
' Next element
'
' Dim tr As HTMLTableRow
' For Each tr In htmlDoc.getElementsByTagName("tbody")(0).getElementsByTagName("tr")
'
' Next tr
End Sub
来源:https://www.cnblogs.com/wzhw2015/p/12355037.html