使用VBA的网页自动化 [英] Webpage Automation using VBA

查看:896
本文介绍了使用VBA的网页自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VBA和编程的新手,我在网上找到了一些自动化网页处理代码。现在我只是想登录电子奥斯卡的网页:

I'm new to VBA and programming in general, and I have found some code online to automate webpage processing. Right now I'm just trying to log into a webpage for e-Oscar:

Do While IE.Busy
    Application.Wait DateAdd("s", 1, Now())
Loop

Set objCollection = IE.document.getElementsByTagName("input")
Set objName = IE.document.getElementsByTagName("name")

i = 0

While i < objCollection.Length
    If objCollection(i).ID = "companyId" Then

        ' Set text for search
        objCollection(i).Value = "companyId"

    Else
        If objCollection(i).ID = "userId" Then
           objCollection(i).Value = "uId"
    Else
        If objCollection(i).ID = "password" Then
           objCollection(i).Value = "pwd"
    Else
        If objCollection(i).ID = "securityMsgAck1" Then
           objCollection(i).Value = True
    'Else
        'If objName(i).Name = "securityMsgAck" Then
           'objName(i).Value = True
    'Else
        'If objCollection(i).ID = "button" Then
           'objCollection(i).Value = True


            ' "Search" button is found
            Set objElement = objCollection(i)
                        End If
                   End If
                End If
            End If
        'End If
    'End If

    i = i + 1
Wend
objElement.Click    ' click button to search

运行AS-IS时。此代码打开我正在尝试自动化的网页,填写公司ID,用户ID,密码,并且似乎选中我确认页面的T& C的框。但是,每当我取消注释securityMsgAck时,它就不再检查该框并给我一个错误:

When ran AS-IS. This code opens up the webpage I'm trying to automate, fills out company id, user id, password, and seems to check the box that I acknowledge the T&C of the page. However, whenever I uncomment out "securityMsgAck" it no longer checks the box and gives me an error:


运行时错误'91' :对象变量或With块变量未设置。\

Run-time error '91': Object variable or With block variable not set.\

如果我注释掉securityMsgAck并取消注释它也会这样做按钮。似乎我的代码试图在没有执行这两个部分的情况下检查框,但是当它们是声明要么失败才能尝试按下它,或者它们完全阻止它。我不太确定......任何建议都会受到赞赏。在此先感谢。

It also does this if I comment out "securityMsgAck" and uncomment out "button". It seems that my code is trying to check the box whenever these two pieces are not executed, but when they are the statement either fails before it can attempt to press it, or they are blocking it altogether. I'm not really sure... any advice would be appreciated. Thanks in advance.

编辑每当我取消注释该代码的任何部分时,我的程序也将不再填写公司ID,userId ,或密码,以及未能检查安全消息框...

Whenever I uncomment out either section of that code, my program also will no longer fill out company Id, userId, or Password, along with failing to check the security message box...

推荐答案

选中该复选框使用以下代码

to check the checkbox use the following code

 ElseIf objcollection(i).ID = "securityMsgAck1" Then
            objcollection(i).Checked = True

这篇关于使用VBA的网页自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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