Hello,
I am fairly new to using VBA and have created my own spreadsheet to track my personal finances. I would like to be able to pull information from my Scottrade www.scottrade.com accounts. Here is what I want done by VBA:
1. Log In to my Account
2. Pull my financial information (i.e. Daily Balances)
I have got Internet Explorer to open up to www.scottrade.com; however, I am getting stuck when I try to click on the Secure Login link to enter my Account# and Password.
Code:
Sub OpenScottrade()
Const cURL = "https://www.scottrade.com"
Const cUsername = xxxx
Const cPassword = xxxx
Dim IE As InternetExplorer
Dim doc As HTMLDocument
Dim SecureLink As HTMLLinkElement
Dim SecureLogIn As HTMLFormElement
Dim LoginForm As HTMLFormElement
Dim UserNameInputBox As HTMLInputElement
Dim PasswordInputBox As HTMLInputElement
Dim SecureLogInLink As HTMLInputButtonElement
Dim SignInButton As HTMLInputButtonElement
Dim HTMLelement As IHTMLElement
Set IE = New InternetExplorer
IE.Visible = True
IE.navigate cURL
Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: Loop
Set SecureLink = IE.document
'Get the only form on the page
Set SecureLogIn = doc.forms(0)
'Open Secure Login
'<a href="#tabs-2" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-5" *******="s_objectID="https://www.scottrade.com/#tabs-2_1";return this.s_oc?this.s_oc(e):true">Secure Login</a>
Set SecureLink = SecureLogIn.elements("s_objectID="https://www.scottrade.com/#tabs-2_1";return this.s_oc?this.s_oc(e):true")
SecureLink.Click
'Get the User Name textbox and populate it
'<input name="account" id="secureUserAccountNumber" type="text" class="login-info" value="" autocapitalize="none" autocorrect="off">
Set UserNameInputBox = LoginForm.elements("account")
UserNameInputBox.Value = cUsername
'Get the password textbox and populate it
'<input name="password" id="secureUserPassword" type="password" class="login-info pw" value="" autocapitalize="none" autocorrect="off" autocomplete="off">
Set PasswordInputBox = LoginForm.elements("ctl00$ct$Password")
PasswordInputBox.Value = cPassword
Set LoginForm = doc.forms(1)
'Get the form input button and click it
'<button src="/content/dam/assets/web/common/blank-pixel.gif" class="secure-login-btn" title="Log In" name="Log In" type="submit"><i class="fa fa-lock"></i> Log In</button>
Set SignInButton = LoginForm.elements("Log In")
SignInButton.Click
'Wait for the new page to load
Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
'Get the HTML document of the new page
Set doc2 = IE.document
'Determine whether login succeeded or not
If InStr(doc.body.innerText, "Invalid Login Information") = 0 Then
MsgBox "Login succeeded"
Else
MsgBox "Login failed"
End If
Debug.Print "Current URL: " & IE.LocationURL
End Sub
Any help would be well appreciated.
Thanks
I am fairly new to using VBA and have created my own spreadsheet to track my personal finances. I would like to be able to pull information from my Scottrade www.scottrade.com accounts. Here is what I want done by VBA:
1. Log In to my Account
2. Pull my financial information (i.e. Daily Balances)
I have got Internet Explorer to open up to www.scottrade.com; however, I am getting stuck when I try to click on the Secure Login link to enter my Account# and Password.
Code:
Sub OpenScottrade()
Const cURL = "https://www.scottrade.com"
Const cUsername = xxxx
Const cPassword = xxxx
Dim IE As InternetExplorer
Dim doc As HTMLDocument
Dim SecureLink As HTMLLinkElement
Dim SecureLogIn As HTMLFormElement
Dim LoginForm As HTMLFormElement
Dim UserNameInputBox As HTMLInputElement
Dim PasswordInputBox As HTMLInputElement
Dim SecureLogInLink As HTMLInputButtonElement
Dim SignInButton As HTMLInputButtonElement
Dim HTMLelement As IHTMLElement
Set IE = New InternetExplorer
IE.Visible = True
IE.navigate cURL
Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: Loop
Set SecureLink = IE.document
'Get the only form on the page
Set SecureLogIn = doc.forms(0)
'Open Secure Login
'<a href="#tabs-2" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-5" *******="s_objectID="https://www.scottrade.com/#tabs-2_1";return this.s_oc?this.s_oc(e):true">Secure Login</a>
Set SecureLink = SecureLogIn.elements("s_objectID="https://www.scottrade.com/#tabs-2_1";return this.s_oc?this.s_oc(e):true")
SecureLink.Click
'Get the User Name textbox and populate it
'<input name="account" id="secureUserAccountNumber" type="text" class="login-info" value="" autocapitalize="none" autocorrect="off">
Set UserNameInputBox = LoginForm.elements("account")
UserNameInputBox.Value = cUsername
'Get the password textbox and populate it
'<input name="password" id="secureUserPassword" type="password" class="login-info pw" value="" autocapitalize="none" autocorrect="off" autocomplete="off">
Set PasswordInputBox = LoginForm.elements("ctl00$ct$Password")
PasswordInputBox.Value = cPassword
Set LoginForm = doc.forms(1)
'Get the form input button and click it
'<button src="/content/dam/assets/web/common/blank-pixel.gif" class="secure-login-btn" title="Log In" name="Log In" type="submit"><i class="fa fa-lock"></i> Log In</button>
Set SignInButton = LoginForm.elements("Log In")
SignInButton.Click
'Wait for the new page to load
Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
'Get the HTML document of the new page
Set doc2 = IE.document
'Determine whether login succeeded or not
If InStr(doc.body.innerText, "Invalid Login Information") = 0 Then
MsgBox "Login succeeded"
Else
MsgBox "Login failed"
End If
Debug.Print "Current URL: " & IE.LocationURL
End Sub
Any help would be well appreciated.
Thanks