VBA to open website and logon with username & password

BrazenMore

New Member
Joined
Apr 14, 2010
Messages
9
Hi
I have the following code which opens a webpage and goes to the username & password fields and logons. However for so strange reason sometimes when the sendkeys sends the username or password it types on the screen incorrectly i.e. the username is brazenmore and sometimes this appears as bbrazenmore or bbrazzzenmore. The code works some of the time any ideas why this happens?

Sub internetlogon()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
'Go to this Web Page!
IE.Navigate "enter web page here"
'Check for good connection to web page loop!
Do
If IE.ReadyState = 4 Then
IE.Visible = False
Exit Do
Else
DoEvents
End If
Loop
'Wait for window to open!
Application.Wait (Now + TimeValue("0:00:01"))
IE.Visible = True
'Send logon information
SendKeys "brazenmore", True
SendKeys "{TAB}", True
SendKeys "brazenmore", True
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Rob

What is your similar question?

If you want to grab the form then perhaps you should see if it's got an id and use GetElemenyByID.

That might be more reliable than trying to use it's index.:)
 
Last edited:
Upvote 0
thanks Norie!

works a treat.


Code:
Sub Test()
    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.application")
    With IE
        .Visible = True
        .navigate ("[URL]http://glenigan-cms.auros.co.uk/default.aspx[/URL]")
        While .Busy Or .readyState <> 4: DoEvents: Wend
    .Document.getElementById("Template_GLE_Login_LoginView1_login_UserName").Focus
    .Document.getElementById("Template_GLE_Login_LoginView1_login_UserName").Value = "YOUR USER NAME HERE"
    .Document.getElementById("Template_GLE_Login_LoginView1_login_Password").Focus
    .Document.getElementById("Template_GLE_Login_LoginView1_login_Password").Value = "YOUR PASSWORD HERE"
    
    .Document.all("Template_GLE_Login_LoginView1_login_LoginButton").Click
        While .Busy Or .readyState <> 4: DoEvents: Wend
        Debug.Print .LocationURL
    End With
 
Upvote 0
Well you might be out of luck there, this code automates IE.

Do you have code that can automate Mozilla via VBA?
 
Upvote 0
I tried testing your code by logging into gmail, but it didn't work. It gets stuck in:
ie.Document.Forms(0).all("User").Value = "me"
 
Upvote 0
found Norie's old code while doing a search.

What part of the user name and password do I need from the java script text to go into the VBA code?

Code:
<!DOCTYPE HTML PUBLIC
    "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
 
<!--
	File Version Start - Do not remove this if you are modifying the file
	Build: 10.0.0
	File Version End
 
	(c) Business Objects 2003-2004.  All rights reserved.
-->
 
 
 
<html class="logon_body">
 
<head>
	<title>Log On to SAP BusinessObjects InfoView</title>    
	
	<!--  These styles are defined here as the images they reference are in PlatformServices and not provided by the application -->
	<!--  TODO: Find a way to use the CSS pseudo class ":hover" so that it works in IE6 -->
	<!--  TODO: Export these styles to an external stylesheet -->
	<style type="text/css">
		.logon_button{
			width:				auto;
			padding:			0 1em;			
			background-repeat:	repeat-x;		
			margin:				0;
			font-family:		Tahoma;
			font-size:			.85em;
			right:				0;
			/* Required for IE 6 */
			position:			absolute;
		}
		
		.logon_button_no_hover {
			background:			url('../../images/center_normal_logon.gif');
		}
		
		.logon_button_hover{		 
			background:			url('../../images/center_hover_logon.gif');					
		}
	</style>
	
    <link rel='stylesheet' type='text/css' name='stylelink' href="../../../InfoViewApp/common/appService.do?service=skinning&resource=stylesheet">
		
	
	
</head>
 
<body ******="loadInit();" class="logon_body">
	
 
 
	******** type="text/javascript">
		function loadInit()
		{	
		
	  	if (this.doLoadInit)
	            doLoadInit();
	            var form = document.forms[0]; // Gets First available form
	            if(form){//if there is an available form
	               form.setAttribute("autocomplete","off"); // Turns off Autocomplete
	            }
	        }
			
	*********>
 
	<div class="logon_body">
		<br>
		<br>
		<div id="messageDiv" class="logon_message">		
			<div id="errors" class="error">   					
 				   					
 			</div>
			<div id="logon_firstInstruction" class="logon_firstInstruction">
				<b>Enter your user information and click Log On. </b>
			</div>
			<div id="logon_secondInstruction" class="logon_secondInstruction">
				(If you are unsure of your account information, contact your system administrator.)
			</div>
			<br>
			<br>
			<div id="logonCredentials">
				
				
					
					
						<!--
	File Version Start - Do not remove this if you are modifying the file
	Build: 10.0.0
	File Version End
 
	(c) Business Objects 2003-2004.  All rights reserved.
-->
 
 
 
<form name="logonForm" method="POST" action="../../../PlatformServices/service/app/logon.object">
 
<input type="hidden" name="qryStr" value="">
 
<input type="hidden" name="cmsVisible" value="false">
 
<input type="hidden" name="cms" value="rhuprdbibo01.Rexelusa.com:6400">
 
<input type="hidden" name="authenticationVisible" value="true">
 
 
<input type="hidden" name="isFromLogonPage" value="true">
<input type="hidden" name="appName" value="SAP BusinessObjects InfoView">
<input type="hidden" name="prodName" value="BusinessObjects">
<input type="hidden" name="sessionCookie" value="true">
<input type="hidden" name="backUrl" value="/listing/main.do">
<input type="hidden" name="backUrlParents" value="1">
<input type="hidden" name="backContext" value="/InfoViewApp">
<input type="hidden" name="persistCookies" value="true">
<input type="hidden" name="useLogonToken" value="true">
<input type="hidden" name="service" value="/InfoViewApp/common/appService.do">
<input type="hidden" name="appKind" value="InfoView">
<input type="hidden" name="loc" value="en">
<input type="hidden" name="reportedIP" value="">
<input type="hidden" name="reportedHostName" value="">
 
******** type="text/javascript" src="../../../PlatformServices/js/accessibility_util.js">*********>
******** type="text/javascript"> 
	function logIPAndHostName()
	{
		var hostaddress = "";
		var hostname = "";
		try {
			hostname = top.location.host; //This works in IE.
			var localhost = new java.net.InetAddress.getLocalHost(); //This only works in FireFox with Java enabled.
			hostaddress = localhost.getHostAddress();
			hostname = localhost.getHostName();
		} catch(e) {
            // do nothing
		}
		document.forms[0].reportedIP.value = hostaddress;
		document.forms[0].reportedHostName.value = hostname;
		return true;
	}
*********>
 
 
 
 
<div class="logon_table">								
					
		<div id="userName" class="logon_input">			 
			<label class="logon_input_label" for="usernameTextEdit" tabIndex=-1>
				User Name:
			</label>				 
				
					
					
					<input type="text" name="username" value="xxxxxx" class="inputTextBox logonTextBox" id="usernameTextEdit">	
					
			
		</div>
		<div id="password" class="logon_input">			
			<label class="logon_input_label" for="passwordTextEdit" tabIndex=-1>
				Password:
			</label>			
			<input type="password" name="password" value="" class="inputTextBox logonTextBox" id="passwordTextEdit">
		</div>
		
			<div id="authentication" class="logon_input">
				
				  <label class="logon_input_label" for="authenticationSelectBox" tabIndex="-1" *******="businessobjects.webutil.accessibility.setFocusOnElement('authenticationSelectBox'); return false;">
					Authentication:
				  </label>
				
				  <select name="authType" class="logonSelectBox" id="authenticationSelectBox"><OPTION value='secEnterprise'>
										Enterprise
								
								
							
								
								
									<OPTION selected value='secLDAP'>
										LDAP
								
								
								
							
								
								
								
									<OPTION value='secWinAD'>
										Windows AD</select>
			</div>
										
</div>
 
 
	
<div id="buttonTable" class="logon_button_pos">	 	 	
		<input type="submit" class="logon_button logon_button_no_hover" value='Log On'
		*******="logIPAndHostName();" ***********="this.className='logon_button logon_button_hover';"
		**********="this.className='logon_button logon_button_no_hover';" />		 	 	
</div>
 
 
 
</form>
							
					
				
			</div>			   
         </div>
    </div>
</body>
</html>

I also need the password entered in here from Norie's old code:

Code:
Sub internetlogon()
   With CreateObject("InternetExplorer.Application")
     .navigate "http://enter web page here"
     .navigate xxxxxx/service/logon.do"
     Do Until .readyState = 4
       DoEvents
     Loop
     DoEvents
     With .document
        .items("username") = "xxxxx"
        .items("usernamesend").submit
     End With
  End With
End Sub

Can someone help out with this?
 
Upvote 0
Hopefully all of the code will appear here:

Code:
<!DOCTYPE HTML PUBLIC
    "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
 
<!--
	File Version Start - Do not remove this if you are modifying the file
	Build: 10.0.0
	File Version End
 
	(c) Business Objects 2003-2004.  All rights reserved.
-->
 
 
 
<html class="logon_body">
 
<head>
	<title>Log On to SAP BusinessObjects InfoView</title>    
	
	<!--  These styles are defined here as the images they reference are in PlatformServices and not provided by the application -->
	<!--  TODO: Find a way to use the CSS pseudo class ":hover" so that it works in IE6 -->
	<!--  TODO: Export these styles to an external stylesheet -->
	<style type="text/css">
		.logon_button{
			width:				auto;
			padding:			0 1em;			
			background-repeat:	repeat-x;		
			margin:				0;
			font-family:		Tahoma;
			font-size:			.85em;
			right:				0;
			/* Required for IE 6 */
			position:			absolute;
		}
		
		.logon_button_no_hover {
			background:			url('../../images/center_normal_logon.gif');
		}
		
		.logon_button_hover{		 
			background:			url('../../images/center_hover_logon.gif');					
		}
	</style>
	
    <link rel='stylesheet' type='text/css' name='stylelink' href="../../../InfoViewApp/common/appService.do?service=skinning&resource=stylesheet">
		
	
	
</head>
 
<body ******="loadInit();" class="logon_body">
	
 
 
	******** type="text/javascript">
		function loadInit()
		{	
		
	  	if (this.doLoadInit)
	            doLoadInit();
	            var form = document.forms[0]; // Gets First available form
	            if(form){//if there is an available form
	               form.setAttribute("autocomplete","off"); // Turns off Autocomplete
	            }
	        }
			
	*********>
 
	<div class="logon_body">
		<br>
		<br>
		<div id="messageDiv" class="logon_message">		
			<div id="errors" class="error">   					
 				   					
 			</div>
			<div id="logon_firstInstruction" class="logon_firstInstruction">
				<b>Enter your user information and click Log On. </b>
			</div>
			<div id="logon_secondInstruction" class="logon_secondInstruction">
				(If you are unsure of your account information, contact your system administrator.)
			</div>
			<br>
			<br>
			<div id="logonCredentials">
				
				
					
					
						<!--
	File Version Start - Do not remove this if you are modifying the file
	Build: 10.0.0
	File Version End
 
	(c) Business Objects 2003-2004.  All rights reserved.
-->
 
 
 
<form name="logonForm" method="POST" action="../../../PlatformServices/service/app/logon.object">
 
<input type="hidden" name="qryStr" value="">
 
<input type="hidden" name="cmsVisible" value="false">
 
<input type="hidden" name="cms" value="rhuprdbibo01.Rexelusa.com:6400">
 
<input type="hidden" name="authenticationVisible" value="true">
 
 
<input type="hidden" name="isFromLogonPage" value="true">
<input type="hidden" name="appName" value="SAP BusinessObjects InfoView">
<input type="hidden" name="prodName" value="BusinessObjects">
<input type="hidden" name="sessionCookie" value="true">
<input type="hidden" name="backUrl" value="/listing/main.do">
<input type="hidden" name="backUrlParents" value="1">
<input type="hidden" name="backContext" value="/InfoViewApp">
<input type="hidden" name="persistCookies" value="true">
<input type="hidden" name="useLogonToken" value="true">
<input type="hidden" name="service" value="/InfoViewApp/common/appService.do">
<input type="hidden" name="appKind" value="InfoView">
<input type="hidden" name="loc" value="en">
<input type="hidden" name="reportedIP" value="">
<input type="hidden" name="reportedHostName" value="">
 
******** type="text/javascript" src="../../../PlatformServices/js/accessibility_util.js">*********>
******** type="text/javascript"> 
	function logIPAndHostName()
	{
		var hostaddress = "";
		var hostname = "";
		try {
			hostname = top.location.host; //This works in IE.
			var localhost = new java.net.InetAddress.getLocalHost(); //This only works in FireFox with Java enabled.
			hostaddress = localhost.getHostAddress();
			hostname = localhost.getHostName();
		} catch(e) {
            // do nothing
		}
		document.forms[0].reportedIP.value = hostaddress;
		document.forms[0].reportedHostName.value = hostname;
		return true;
	}
*********>
 
 
 
 
<div class="logon_table">								
					
		<div id="userName" class="logon_input">			 
			<label class="logon_input_label" for="usernameTextEdit" tabIndex=-1>
				User Name:
			</label>				 
				
					
					
					<input type="text" name="username" value="xxxxxx" class="inputTextBox logonTextBox" id="usernameTextEdit">	
					
			
		</div>
		<div id="password" class="logon_input">			
			<label class="logon_input_label" for="passwordTextEdit" tabIndex=-1>
				Password:
			</label>			
			<input type="password" name="password" value="" class="inputTextBox logonTextBox" id="passwordTextEdit">
		</div>
		
			<div id="authentication" class="logon_input">
				
				  <label class="logon_input_label" for="authenticationSelectBox" tabIndex="-1" *******="businessobjects.webutil.accessibility.setFocusOnElement('authenticationSelectBox'); return false;">
					Authentication:
				  </label>
				
				  <select name="authType" class="logonSelectBox" id="authenticationSelectBox"><OPTION value='secEnterprise'>
										Enterprise
								
								
							
								
								
									<OPTION selected value='secLDAP'>
										LDAP
								
								
								
							
								
								
								
									<OPTION value='secWinAD'>
										Windows AD</select>
			</div>
										
</div>
 
 
	
<div id="buttonTable" class="logon_button_pos">	 	 	
		<input type="submit" class="logon_button logon_button_no_hover" value='Log On'
		*******="logIPAndHostName();" ***********="this.className='logon_button logon_button_hover';"
		**********="this.className='logon_button logon_button_no_hover';" />		 	 	
</div>
 
 
 
</form>
							
					
				
			</div>			   
         </div>
    </div>
</body>
</html>
 
Upvote 0
Here is some more of the code from the inside javascript part:

Code:
form name="logonForm" method="POST" action="../../../PlatformServices/service/app/logon.object">
 
<input type="hidden" name="qryStr" value="">
 
<input type="hidden" name="cmsVisible" value="false">
 
<input type="hidden" name="cms" value="rhuprdbibo01.Rexelusa.com:6400">
 
<input type="hidden" name="authenticationVisible" value="true">
 
 
<input type="hidden" name="isFromLogonPage" value="true">
<input type="hidden" name="appName" value="SAP BusinessObjects InfoView">
<input type="hidden" name="prodName" value="BusinessObjects">
<input type="hidden" name="sessionCookie" value="true">
<input type="hidden" name="backUrl" value="/listing/main.do">
<input type="hidden" name="backUrlParents" value="1">
<input type="hidden" name="backContext" value="/InfoViewApp">
<input type="hidden" name="persistCookies" value="true">
<input type="hidden" name="useLogonToken" value="true">
<input type="hidden" name="service" value="/InfoViewApp/common/appService.do">
<input type="hidden" name="appKind" value="InfoView">
<input type="hidden" name="loc" value="en">
<input type="hidden" name="reportedIP" value="">
<input type="hidden" name="reportedHostName" value="">
 
******** type="text/javascript" src="../../../PlatformServices/js/accessibility_util.js">*********>
******** type="text/javascript"> 
	function logIPAndHostName()
	{
		var hostaddress = "";
		var hostname = "";
		try {
			hostname = top.location.host; //This works in IE.
			var localhost = new java.net.InetAddress.getLocalHost(); //This only works in FireFox with Java enabled.
			hostaddress = localhost.getHostAddress();
			hostname = localhost.getHostName();
		} catch(e) {
            // do nothing
		}
		document.forms[0].reportedIP.value = hostaddress;
		document.forms[0].reportedHostName.value = hostname;
		return true;
	}
*********>
 
 
 
 
<div class="logon_table">								
					
		<div id="userName" class="logon_input">			 
			<label class="logon_input_label" for="usernameTextEdit" tabIndex=-1>
				User Name:
			</label>				 
				
					
					
					<input type="text" name="username" value="270010437" class="inputTextBox logonTextBox" id="usernameTextEdit">	
					
			
		</div>
		<div id="password" class="logon_input">			
			<label class="logon_input_label" for="passwordTextEdit" tabIndex=-1>
				Password:
			</label>			
			<input type="password" name="password" value="" class="inputTextBox logonTextBox" id="passwordTextEdit">
		</div>
		
			<div id="authentication" class="logon_input">
				
				  <label class="logon_input_label" for="authenticationSelectBox" tabIndex="-1" *******="businessobjects.webutil.accessibility.setFocusOnElement('authenticationSelectBox'); return false;">
					Authentication:
				  </label>
				
				  <select name="authType" class="logonSelectBox" id="authenticationSelectBox"><OPTION value='secEnterprise'>
										Enterprise
								
								
							
								
								
									<OPTION selected value='secLDAP'>
										LDAP
								
								
								
							
								
								
								
									<OPTION value='secWinAD'>
										Windows AD</select>
			</div>
										
</div>
 
 
	
<div id="buttonTable" class="logon_button_pos">	 	 	
		<input type="submit" class="logon_button logon_button_no_hover" value='Log On'
		*******="logIPAndHostName();" ***********="this.className='logon_button logon_button_hover';"
		**********="this.className='logon_button logon_button_no_hover';" />		 	 	
</div>
 
 
 
</form>
							
					
				
			</div>			   
         </div>
    </div>
</body>
</html>

Sorry for this mess.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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