ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel VBA Macro to input data on website - problem with HTML language (https://www.excelbanter.com/excel-programming/447293-excel-vba-macro-input-data-website-problem-html-language.html)

Excel_Phil

Excel VBA Macro to input data on website - problem with HTML language
 
Hello Everyone,

Im using the code below to successfully log on a website with username and password. However, after I log in, I need to fill a form with 6 input boxes, each with 4 digits, the 5th with 3 digits. Once I type (manually), the first 4 digits, it automatically goes to the next tab.

With the code below, I looked into the website HTML code (and looked for the "name" part of the login and password). But for these 6 boxes I cant get in to work using the same logic. My failed additions to the code are in bold and bigger size.

Running the code with my additions (see below) I get a type mismatch error 13.

I appreciate any help!

Sub Test()

Const cURL = "http://mail.google.com" 'Enter the web address here
Const cUsername = "XXXXXX" 'Enter your user name here
Const cPassword = "XXXXXX" 'Enter your Password here
Const cBox1 = "1234" ' This is my addition


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
Dim qt As QueryTable
Dim Box1 As HTMLInputElement ' This is my addition


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
'input name="Email" id="Email" size="18" value="" class="gaia le val" type="text"

Set UserNameInputBox = LoginForm.elements("Email")
UserNameInputBox.Value = cUsername

'Get the password textbox and populate it
'input name="Passwd" id="Passwd" size="18" class="gaia le val" type="password"


Set PasswordInputBox = LoginForm.elements("Passwd")
PasswordInputBox.Value = cPassword

'Get the form input button and click it
'input class="gaia le button" name="signIn" id="signIn" value="Sign in" type="submit"

Set SignInButton = LoginForm.elements("signIn")
SignInButton.Click

'Wait for the new page to load

Do While IE.ReadyState < READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

Set Box1 = LoginForm.elements("intermedica") ' This is my addition
Box1.Value = Box1 ' This is my addition


End Sub






Here is the HTML code that I cant figure out:

<td align="right" valign="baseline"Carteirinha:&nbsp;</td
<td colspan="2"
<input type="text" size="4" maxlength="4" class="form" name="intermedica" onKeyUp="return autoTab(this,4,event);"
<input type="text" size="4" maxlength="4" class="form" name="intermedica" onKeyUp="return autoTab(this,4,event);"
<input type="text" size="4" maxlength="4" class="form" name="intermedica" onKeyUp="return autoTab(this,4,event);"
<input type="text" size="4" maxlength="4" class="form" name="intermedica" onKeyUp="return autoTab(this,4,event);"
<input type="text" size="3" maxlength="3" class="form" name="intermedica" onKeyUp="return autoTab(this,3,event);"
<input type="text" size="4" maxlength="4" class="form" name="intermedica"&nbsp;&nbsp;&nbsp;
</td
</tr
<tr
<td colspan="3"&nbsp;</td
</tr
<tr
<td colspan="3" align="center"<input class="form_b" id="act_B" type="button" value="Buscar" name="act_B" onClick="javascript:PesquisaAss();"&nbsp;&nbsp;<i nput class="form_b" type="reset" value="Limpar" name="limpar"</td
</tr
<tr
<td colspan="3"<strong<font color="#FF6600"&nbsp;&nbsp;</font</strong</td
</tr

<tr
<td colspan="3"<strong<font color="#FF6600"&nbsp;</font</strong</td
</tr




</table
<br/

</form



Thanks Again!!

Walter Briscoe

Excel VBA Macro to input data on website - problem with HTML language
 
In message of Thu, 4 Oct 2012
23:17:05 in microsoft.public.excel.programming, Excel_Phil <Excel_Phil.a
writes

Hello Everyone,

Im using the code below to successfully log on a website with username
and password. However, after I log in, I need to fill a form with 6
input boxes, each with 4 digits, the 5th with 3 digits. Once I type
(manually), the first 4 digits, it automatically goes to the next tab.

With the code below, I looked into the website HTML code (and looked for
the "name" part of the login and password). But for these 6 boxes I cant
get in to work using the same logic. My failed additions to the code are
in bold and bigger size.


[snip]

I use DebugBar from
http://www.debugbar.com/ for such problems. It has a
control, which can be put over any part of an IE screen and displays
relevant information.
Once I know what it is, I can usually work out how to access it from
VBA. YMMV
--
Walter Briscoe


All times are GMT +1. The time now is 08:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com