从现有(打开)的 Internet Explorer 页面运行我的 VBA 代码

乔纳森

我想在我已经打开并登录的特定 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

乔纳森

调用这个函数帮我解决了这个问题。

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

VBA:从现有打开的 Internet Explorer 选项卡复制数据/文本

当使用 VBA 直接从 Internet Explorer 打开 CSV 文件时,我无法与该文件进行交互。

在Internet Explorer的新窗口中运行javascript代码

vba Internet Explorer 删除对象

Excel VBA Internet Explorer单击没有ID的按钮

我的导航无法在Internet Explorer上运行

YouTube 嵌入代码 Internet Explorer 11

打开时Internet Explorer崩溃

Java脚本代码无法在Internet Explorer中运行,而在Google Chrome中可以正常运行

Internet Explorer中的所有“关于:”页面是什么?

使用VBA更改Internet Explorer编码

Excel VBA错误462和Internet Explorer

vba拦截Internet Explorer链接单击

VBA Internet Explorer 网页链接选择

如果调试器关闭,Internet Explorer会发出运行代码

如何使用 VBA 在 Internet Explorer 页面上选择单选按钮?

我可以在Internet Explorer 11的调试器中修改Javascript代码吗?

有没有一种 VBA 方法可以让 Internet Explorer 放弃对文件的控制?

当按钮没有关联的“名称”时,请使用Excel VBA在Internet Explorer中单击按钮

阻止我的网站在Internet Explorer中运行

我无法使用以下代码通过 Internet Explorer 登录网站。它说运行时错误 424 - 需要对象

Minecraft链接打开Internet Explorer,而不是Chrome

Jar文件使用Internet Explorer打开

JavaFX - 仅在 Internet Explorer 中打开 url

JNLP Extension无法在Internet Explorer中打开

在Internet Explorer 11中打开固定的站点

VBA查询-调整现有代码

是否可以仅通过HTML / JavaScript从Internet Explorer中呈现的页面打开Microsoft Edge?

使Internet Explorer 9打开页面,并通过邮件桌面客户端提供eml文件