|
我之前写了一段代码,用于获取一个内部网站的查询内容,是基于IE的,运行正常。但现在IE不受支持了,需要改成使用Edge来查询,修改的代码如下,但执行到语句“[color=var(--highlight-keyword)]Set[color=var(--highlight-color)] myButton = appEdge.Document.getElementById([color=var(--highlight-variable)]"btn_mainsearch"[color=var(--highlight-color)])”
[color=var(--highlight-keyword)]时总是报错“Object doesn't support his property or method”,看来Edge已经不支持这种对按钮的定义了,请问是否还有其它变通方式?Sub Query_Edge()
Application.ScreenUpdating = False
Dim edgePath As String
Dim appEdge As Object
Dim myButton As Object
Dim i As Range
Dim iRow As Long
edgePath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
Set appEdge = CreateObject("Shell.Application")
appEdge.ShellExecute edgePath, "http://test.abc.com/Home", "", "", 1
Do Until Not appEdge.Windows(0) Is Nothing
DoEvents
Loop
Set appEdge = appEdge.Windows(0)
Do While appEdge.Busy Or Not appEdge.readyState = 4
DoEvents
Loop
Set myButton = appEdge.Document.getElementById("btn_mainsearch")
Dim htmlDoc As HTMLDocument: Set htmlDoc = appEdge.Document
For Each i In Selection
iRow = i.Row
htmlDoc.getElementById("box_mainsearch").Value = Cells(iRow, "A").Value
Application.Wait (Now + TimeValue("0:00:01"))
myButton.Click
Do While appEdge.Document.readyState <> "complete"
DoEvents
Loop
Do While htmlDoc.getElementById("table_result") Is Nothing
DoEvents
Loop
If Not htmlDoc.getElementById("table_result").getElementsByTagName("td")(11) Is Nothing Then
Cells(iRow, "O") = htmlDoc.getElementById("table_result").getElementsByTagName("td")(11).innerText
End If
If Not htmlDoc.getElementById("table_result").getElementsByTagName("td")(12) Is Nothing Then
Cells(iRow, "R") = htmlDoc.getElementById("table_result").getElementsByTagName("td")(12).innerText
End If
If Not htmlDoc.getElementById("table_result").getElementsByTagName("td")(13) Is Nothing Then
Cells(iRow, "Q") = htmlDoc.getElementById("table_result").getElementsByTagName("td")(13).innerText
End If
If Not htmlDoc.getElementById("table_result").getElementsByTagName("td")(9) Is Nothing Then
Cells(iRow, "G") = htmlDoc.getElementById("table_result").getElementsByTagName("td")(9).innerText
End If
Next i
Application.ScreenUpdating = True
End Sub
|
|