VBA Pull Data From a Website

jpoch12

New Member
Joined
Jun 30, 2015
Messages
1
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
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top