我試圖登錄到使用IE作爲瀏覽器的電子郵件帳戶,這是所有使用的過人之處VBA環境實現自動化,到目前爲止,我有以下幾點:IE登錄自動化 - 如何按提交按鈕?
Option Explicit
Sub login()
Const cURL = "https://login.microsoftonline.com/"
Const cUsername = "XXXX" 'REPLACE XXXX WITH YOUR USER NAME
Const cPassword = "YYYY" 'REPLACE YYYY WITH YOUR PASSWORD
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
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
Set UserNameInputBox = LoginForm.elements("cred_userid_inputtext")
UserNameInputBox.Value = cUsername
'Get the password textbox and populate it
Set PasswordInputBox = LoginForm.elements("cred_password_inputtext")
PasswordInputBox.Value = cPassword
'Get the form input button and click it
Set SignInButton = LoginForm.elements("cred_sign_in_button")
SignInButton.Click
'Wait for the new page to load
Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
Debug.Print "Current URL: " & IE.LocationURL
End Sub
使用此代碼,用戶名和密碼輸入正常,但當我嘗試按下「提交」按鈕時出現問題,我得到一個運行時錯誤,並不知道爲什麼,但我認爲它可能是一個JavaScript對象,但無法弄清楚如何讓VBA按下它。任何幫助,將不勝感激。
只需使用'LoginForm.Submit' – 2014-12-04 20:28:04
你能爲提交按鈕提供相關的HTML代碼?什麼運行時錯誤正在發生? – cheezsteak 2014-12-04 20:37:39