Automatic Login using VBA

zohebn

New Member
Joined
Jun 3, 2013
Messages
4
I have searched the web tying to figure out why my code for this doesn't work. I am trying to automate a set of commands on a website, but am having issues just getting it to login. It shows me an error at the following point in .Key.Value = "mylogin" saying object doesn't support
My Code is

Code:
Sub login()
    Dim ie As InternetExplorer
    Dim C
    Dim ULogin As Boolean, ieForm
    Dim MyPass As String, MyLogin As String
    Dim ieDoc As Object
     
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "https://www.foreclosure.com/login"
     
     'Loop until ie page is fully loaded
    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop
    
    Set ieDoc = ie.Document
    With ieDoc.forms(0)
    .Key.Value = "mylogin"
    .Password.Value = "mypass"
        .submit
    End With
     
    Do While ie.Busy: DoEvents: Loop
        Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
             
                        
            Do While ie.Busy: DoEvents: Loop
                Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
                     
                     'ie.Quit
                    Set ie = Nothing
  End Sub

Here is the relevant code from the source code
HTML:
*********><div class="container"><div class="row"><div class="col-md-6 col-md-offset-1"><h3>Sign In</h3><div id="contEmailPassword"><p class="bp_10">Enter your email and password below:</p><form name="login" id="login_password" action="https://www.foreclosure.com/login.html" method="post" style="margin-bottom: 0px;"><fieldset><div class="form-group control-group"><input autocomplete="on" name="key" type="text" value="" placeholder="Email" class="form-control bm_0 required"></div><div class="form-group control-group"><input name="password" size="20" value="" autocomplete="on" type="password" id="password" style="margin-bottom:0px;" placeholder="Password" class="form-control required"></div><div class="form-group control-group"><input type="submit" class="btn btn-primary" value="Sign In" id="btnLoginUsernamePassword" style="margin-bottom:0px;"/><span style="margin-left:10px;"><a href="/lostpassword.html">Forgot Password?</a></span></div>
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
The input fields are in the second form, not the first, so try:
Code:
With ieDoc.forms(1)
 
Upvote 0
Thanks John! It worked perfect for that website. Though I realized I had been trying to login to the wrong website. The one that I want to login to has the following source code:

HTML:
<!-- %--@ Register src="TopForMaster.ascx" tagname="TopForMaster" tagprefix="uc1" % --><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title></title><link rel="Stylesheet" href="Masters/ExpMasterStyleSheet.css" />    ****** http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>Foreclosure Information and Listing Service Client Login and Password Recovery</title>****** name="Keywords" content="foreclosure, Houston, Fort Bend, Montgomery, Galveston, Brazoria, Nueces county, Constable Sale, Sheriff Foreclosure"/>****** name="Description" content="Foreclosure Information and Listing Service - Actual, True, Houston-Area Pre-Foreclosures. Counties include Houston, Fort Bend, Montgomery, Galveston, Brazoria, Nueces county  "/>****** name="Expires" content="never"/>****** name="Distribution" content="global"/>****** name="AUTHOR" content="Foreclosure Information and Listing Service"/>****** name="ROBOTS" content="ALL"/></head><body>    <form method="post" action="Login.aspx" id="form1"><div class="aspNetHidden"><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY3OTExMTY3MWRkvE6JE7Of8UuhzKpyoqoZkvps0YLzl5ijQl/Arlx3YtQ=" /></div><div class="aspNetHidden">	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAR5zpaAxILlfUjW24zQgy0zYZAMGPiZQnNpn53hST03Lpi936R4uKPKq7GDLght46TKVGVpQFYKY8UGA3Ni0RbrJ1nLVJMr+fq67M68k9JnYqivtAFvYUvxv582x9f09vQ=" /></div>    <div><table border="0" cellpadding="0" cellspacing="0" style='border-collapse:collapse;table-layout:fixed;width:675pt;margin-left: auto;margin-right: auto;'><!-- u-c-1:TopForMaster I-D="Top-For-Master1"         run-at="se-rver" / --><!-- end of menu --><tr><td class="xl313" style="border-right:.5pt solid white;border-left:none">            <b class="pageTitle">Login and Password Recovery</b><br><br><br><table border=0 cellpadding=6 cellspacing=0 style="border: 1px solid #999; width: 350px;">	<tr>		<td Colspan=2 style="background-color: #EBEBEB;">Client Login</td>	</tr>	<tr>		<td align=right>Username:</td>		<td><input name="ctl00$MainLeftContent$txtUsername" type="text" id="MainLeftContent_txtUsername" style="width:185px;" />        </td>	</tr>	<tr>		<td align=right>Password:</td>		<td><input name="ctl00$MainLeftContent$txtPassword" type="password" id="MainLeftContent_txtPassword" style="width:185px;" /></td>	</tr>	<tr>		<td align=right></td>		<td>            <input type="submit" name="ctl00$MainLeftContent$btnLoginSubmit" value="Login >>" id="MainLeftContent_btnLoginSubmit" style="width:185px;" />                </td>	</tr></table><br><br><table border=0 cellpadding=6 cellspacing=0 style="border: 1px solid #999; width: 350px;">	<tr>		<td Colspan=2 style="background-color: #EBEBEB;"><a href="javascript:window.parent.location.href='https://www.foreclosehouston.com/Password-Recovery'">Password Recovery</a></td>	</tr></table><br><br><!-- <ul><LI> <b><a href="create_account.html" style="color: #00C;">Click here to create a New Client Account</a></b></LI><LI> <b><a href="subscribe.html" style="color: #00C;">Click here to Subscribe to Our Newsletter</a></b></LI></ul>-->  </td></tr></table>    </div>    </form></body>

The problem I am having is understanding the control key since apparently what I have been trying hasn't worked.
Code:
Sub login()
    Dim ie As InternetExplorer
    Dim C
    Dim ULogin As Boolean, ieForm
    Dim MyPass As String, MyLogin As String
    Dim ieDoc As Object
     
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "https://www.foreclosehouston.com/login"
     
     'Loop until ie page is fully loaded
    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop
     
    
    Set ieDoc = ie.Document
    With ieDoc.forms(1)
    .UserName.Value = "user"
    .Password.Value = "pass"
        .submit
    End With
     
    Do While ie.Busy: DoEvents: Loop
        Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
             
                        
            Do While ie.Busy: DoEvents: Loop
                Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
                     
                     'ie.Quit
                    Set ie = Nothing
  End Sub
 
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,634
Members
449,460
Latest member
jgharbawi

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