【发布时间】:2020-09-26 06:29:25
【问题描述】:
我想在我已经打开并登录的特定 Internet Explorer 页面上运行我的 VBA 宏。
这是因为我必须先登录我的帐户并绕过验证码。 在这一年中,我必须向数百人发送这条极其重复的信息。
以下问题是我打开了一个全新的页面,我将无法绕过验证码。
Dim IE As InternetExplorer
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate ("website")
IE.Visible = True
End Sub
解决方案
Sub TestGetIE()
Dim IE As Object
'GetIE runs the Functoin we have created below
Set IE = GetIE("website opened in IE here ")
WaitFor IE
end sub
Function GetIE(sLocation As String) As Object
Dim objShell As Object, objShellWindows As Object, o As Object
Dim sURL As String
Dim retVal As Object
Set retVal = Nothing
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
For Each o In objShellWindows
'Loop through all the opened internet explorer pages
sURL = ""
'Loops through all the pages opened on internet explorer
'Then we will tell our macro to work on that page
sURL = o.LocationURL
If sURL Like sLocation & "*" Then
Set retVal = o
Exit For
End If
Next o
Set GetIE = retVal
End Function
【问题讨论】:
-
您可以找到每个现有的 IE 窗口并检查其 URL 以找到您想要的,然后使用该窗口 - 例如。见stackoverflow.com/questions/31167200/…
-
@TimWilliams 谢谢你让它工作。
标签: vba internet-explorer