运行时错误“ 91”-我花了数周的时间来解决这个问题

时间:2019-07-08 16:53:43

标签: excel vba

我的VBA知识有限。我所知道的大多数是一起复制/粘贴代码,直到我开始工作。我一直在尝试提出一些代码,这些代码将使我能够自动登录到我的银行(Chase)。运行宏,它会将您重定向到站点,为您填写凭据,然后您就可以登录了。无论我尝试使用什么代码,最终都使用相同的代码

  

运行时错误“ 91”

通常在同一位置:

UserNameInputBox.Value = cUsername

下面是我所拥有的(减去我的凭据)。同样,我的知识很少,因此请尝试简化对我的解释。感谢您的帮助。

Sub Chase()
    Const cURL = "https://www.chase.com/"
    Const cUsername = "XXXXXX"
    Const cPassword = "XXXXXX"

    Dim IE As InternetExplorer
    Dim doc As HTMLDocument
    Dim LoginForm As HTMLFormElement
    Dim UserNameInputBox As HTMLInputElement
    Dim PasswordInputBox As HTMLInputElement
    Dim SignInButton As HTMLInputButtonElement
    Dim HTMLelement As IHTMLElement
    Dim qt As QueryTable

    Set IE = New InternetExplorer

    IE.Visible = True
    IE.Navigate cURL

    'Wait for initial page to load
    Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

    Set doc = IE.Document

    'Get the only form on the page
    Set LoginForm = doc.forms(0)

    'Get the User Name textbox and populate it
    'input name="userId" id="userId-input-field" size="18" value="" class="jpui input logon-xs-toggle clientSideError" type="text"

    Set UserNameInputBox = LoginForm.elements("Username")
    UserNameInputBox.Value = cUsername

    'Get the password textbox and populate it
    'input name="password" id="password-input-field" size="18" class="jpui input logon-xs-toggle clientSideError" type="password"

    Set PasswordInputBox = LoginForm.elements("Password")
    PasswordInputBox.Value = cPassword

    'Get the form input button and click it
    'button class="jpui button focus fluid primary" name="Sign in" id="signin-button" value="Sign in" type="submit"

    Set SignInButton = LoginForm.elements("Sign in")
    SignInButton.Click

    'Wait for the new page to load
    Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
End Sub

0 个答案:

没有答案