VBA单击按钮 [英] VBA to click on button

查看:94
本文介绍了VBA单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用VBA发出Internet Explorer按钮问题.

Issues with Internet Explorer button using VBA.

我需要有关使用vba单击按钮的帮助.问题是当我自动输入用户名和密码时,该按钮不可单击.仅当我手动输入用户名和密码时,它才可单击.我的代码可以与网站上的其他按钮(除了该按钮)一起使用.

I need help with clicking a button using vba. The issue is that the button is not clickable when I automatically put in the username and password. It is only clickable when I manually type in the username and password. My code works with other buttons on the website except for this one.

'这是我的代码部分,输入用户名,密码并应单击该按钮.

'Here is the part of my code that enters the username, password and supposed to click on the button.

    Set HTMLInput = HTMLDoc.getElementById("USER")
    HTMLInput.Value = "user"

    Set HTMLInput = HTMLDoc.getElementById("Password")
    HTMLInput.Value = "password"

    Set HTMLButton= HTMLDoc.getElementById("subBtn")
    HTMLButton.Click

'这是按钮信息

<button type="submit" class="btn btn-primary ng-scope" data-ng-click="saveUserID()" id="subBtn" translate="signin.signin">Sign In</button>

我读过某个地方,我可以使用Application.sendkeys"username",True来模拟键盘上的键入,以查看按钮是否可单击,但我也无法使其正常工作.有没有其他方法可以使该按钮可点击?

I've read somewhere that I can use the Application.sendkeys"username",True to simulate typing on the keyboard to see if the button will be clickable but I also cannot get that to work. Is there another way to make this button clickable?

推荐答案

将Disabled属性更改为False

Change the disabled attribute to False

Option Explicit
'VBE > Tools > References: Microsoft Internet Controls
Public Sub Login()
    Dim ie As New InternetExplorer
    With ie
        .Visible = True
        .Navigate2 "https://workforcenow.adp.com/workforcenow/login.html"

        While .Busy Or .readyState < 4: DoEvents: Wend

        With .document
            .querySelector("#user_id").Value = "something"
            .querySelector("#password").Value = "somethingElse"

            With .querySelector("#subBtn")
                .disabled = False
                .Click
            End With
            Stop '< delete me later
        End With

        While .Busy Or .readyState < 4: DoEvents: Wend
        'other stuff post login
        .Quit
    End With
End Sub

这篇关于VBA单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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