我正在创建一个宏来从公共银行网站获取传真号码。
我已经编写了足够的代码来访问该站点,从下拉列表中进行选择,然后更改下拉列表中的选择。但是,当我使用 FireEvent ("onChange") 时,它不会触发网页更新。
我已经搜索了答案,但没有找到任何答案。
网站: https ://www.atb.com/contact-us/Pages/branch-locator.aspx
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
Sub test()
Dim ieExplorer As New InternetExplorerMedium
Dim ieField As Object
Dim ieSubmit As Object
Dim ieSelect As Object
Dim iebutton As Object
Dim buttCounter As Integer
Dim objOption As Object
Dim objCount As Integer
Dim ieForm As Object
Dim intRow As Long, faxNum As String
intRow = 2
With ieExplorer
.Visible = True
.Navigate "https://www.atb.com/contact-us/Pages/branch-locator.aspx"
Sleep 1000
Sleep 1000
Sleep 1000
Sleep 1000
Sleep 1000
Sleep 1000
Sleep 1000
Set ieSelect = .Document.getElementsByTagName("select")
Do While o < ieSelect.Length
If ieSelect(o).ID = "ba" Then
For Each i In ieSelect(o).Options
If i.Value <> "null" Then
ieSelect(o).Focus
i.Selected = True
ieSelect(o).FireEvent "onchange"
Set ieField = .Document.getElementsByTagName("p")
Do While x < ieField.Length
If InStr(ieField(x).innertext, "FAX") Then
Cells(intRow, "A").Value = i.Value
Cells(intRow, "B").Value = ieField(x).innertext
intRow = intRow + 1
End If
Loop
End If
Next
End If
o = o + 1
Loop
End With
End Sub