Web Scraper 不会填充我的 VBA 代码启动的子 window
Web Scraper won't fill in a child window that my VBA code launches
我在 VBA 中有以下代码,它打开一个 IE 页面,填写它,然后单击一个按钮打开一个新的 IE window。但是,我的代码无法填写新 window 的第一个下拉列表。任何帮助将不胜感激。
Sub Van()
Dim IE As Object
Dim IE2 As Object
Set IE = CreateObject("InternetExplorer.Application")
'Set IE2 = CreateObject("InternetExplorer.Application")
IE.navigate ("website")
IE.Visible = True
Do
DoEvents
Loop Until IE.readyState = 4
Set d = IE.document
'Code now clicks on buttons or dropdowns etc
Application.Wait (Now + TimeValue("00:00:03"))
Set IE2 = GetIE("pop-up page")
WaitFor IE2
'Tried this too
'Application.Wait (Now + TimeValue("00:00:05"))
IE2.document.getElementsByTagName("select")(0).Value = "X"
'Also tried the line below
'IE2.document.GetElementsbyname("name")(0).SelectedIndex = 1
End Sub
Function GetIE(sAddress As String) As Object
Dim objShell As Object, objShellWindows As Object, o As Object
Dim retVal As Object, sURL As String
Set retVal = Nothing
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
'see if IE is already open
For Each o In objShellWindows
sURL = ""
On Error Resume Next
sURL = o.LocationURL
On Error GoTo 0
If sURL <> "" Then
'MsgBox sURL
If sURL = sAddress Then
Set retVal = o
Exit For
End If
End If
Next o
Set GetIE = retVal
End Function
Sub WaitFor(IE)
Do
DoEvents
Loop Until IE.readyState = 4
End Sub
当您尝试访问 select 时,弹出窗口中的页面可能未完全加载 - 尝试添加一个等待循环,直到加载完成。我喜欢将 "wait" 循环拉出到可重复使用的函数中:
Set IE2 = GetIE("https://secure.apia.com.au/NASApp/apia/CRQuoteServlet?" & _
"pageAction=openModelSelectionWindow¤tSequenceNumber=")
WaitFor IE2
IE2.document.getElementsByTagName("select")(0).Value = "JAY"
等待:
Sub WaitFor(IE)
Do
DoEvents
Loop Until IE.readystate = 4
End sub
我在 VBA 中有以下代码,它打开一个 IE 页面,填写它,然后单击一个按钮打开一个新的 IE window。但是,我的代码无法填写新 window 的第一个下拉列表。任何帮助将不胜感激。
Sub Van()
Dim IE As Object
Dim IE2 As Object
Set IE = CreateObject("InternetExplorer.Application")
'Set IE2 = CreateObject("InternetExplorer.Application")
IE.navigate ("website")
IE.Visible = True
Do
DoEvents
Loop Until IE.readyState = 4
Set d = IE.document
'Code now clicks on buttons or dropdowns etc
Application.Wait (Now + TimeValue("00:00:03"))
Set IE2 = GetIE("pop-up page")
WaitFor IE2
'Tried this too
'Application.Wait (Now + TimeValue("00:00:05"))
IE2.document.getElementsByTagName("select")(0).Value = "X"
'Also tried the line below
'IE2.document.GetElementsbyname("name")(0).SelectedIndex = 1
End Sub
Function GetIE(sAddress As String) As Object
Dim objShell As Object, objShellWindows As Object, o As Object
Dim retVal As Object, sURL As String
Set retVal = Nothing
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
'see if IE is already open
For Each o In objShellWindows
sURL = ""
On Error Resume Next
sURL = o.LocationURL
On Error GoTo 0
If sURL <> "" Then
'MsgBox sURL
If sURL = sAddress Then
Set retVal = o
Exit For
End If
End If
Next o
Set GetIE = retVal
End Function
Sub WaitFor(IE)
Do
DoEvents
Loop Until IE.readyState = 4
End Sub
当您尝试访问 select 时,弹出窗口中的页面可能未完全加载 - 尝试添加一个等待循环,直到加载完成。我喜欢将 "wait" 循环拉出到可重复使用的函数中:
Set IE2 = GetIE("https://secure.apia.com.au/NASApp/apia/CRQuoteServlet?" & _
"pageAction=openModelSelectionWindow¤tSequenceNumber=")
WaitFor IE2
IE2.document.getElementsByTagName("select")(0).Value = "JAY"
等待:
Sub WaitFor(IE)
Do
DoEvents
Loop Until IE.readystate = 4
End sub