从现有的(打开的)Internet Explorer页面运行我的VBA代码 [英] Run my VBA code from a existing (opened) internet explorer page

查看:156
本文介绍了从现有的(打开的)Internet Explorer页面运行我的VBA代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我已经打开并登录的特定Internet Explorer页面上运行我的VBA宏.

I would like to run my VBA macro on a specific internet explorer page that I have already opened and logged into .

这是因为我必须登录到我的帐户并首先绕过验证码. 在这一年中,我必须将这一极为重复的信息发送给数百人.

This is because I have to login to my account and bypass the captcha code first. I have to send this extremely repetitive message to over a couple hundred people over the course of the year.

以下问题是我正在打开一个全新的页面,而我将无法绕过验证码.

Problem with the following is that I am opening up a brand new page and I wont be able to bypass the captcha.

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

推荐答案

调用此函数可以帮助我解决它.

Calling upon this function helped me solve it.

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

这篇关于从现有的(打开的)Internet Explorer页面运行我的VBA代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆