VBA for auto login - Not autofilling fields

Crool

New Member
Joined
Jul 7, 2010
Messages
12
The page i have been loggin on to has been updated and now the code i have been using doesn't work.

Code:
[TABLE="width: 705"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Dim HTMLDoc As HTMLDocument
[/TD]
[/TR]
[TR]
[TD]Dim MyBrowser As InternetExplorer[/TD]
[/TR]
[TR]
[TD]Sub XXXx()[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Dim MyHTML_Element As IHTMLElement
[/TD]
[/TR]
[TR]
[TD]Dim MyURL As String[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]On Error GoTo Err_Clear[/TD]
[/TR]
[TR]
[TD]MyURL = "https://www.xxx.com"[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Set MyBrowser = New InternetExplorer[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]MyBrowser.Silent = True[/TD]
[/TR]
[TR]
[TD]MyBrowser.navigate MyURL[/TD]
[/TR]
[TR]
[TD]MyBrowser.Visible = True[/TD]
[/TR]
[TR]
[TD]Do[/TD]
[/TR]
[TR]
[TD]Loop Until MyBrowser.readyState = READYSTATE_COMPLETE[/TD]
[/TR]
[TR]
[TD]Set HTMLDoc = MyBrowser.document[/TD]
[/TR]
[TR]
[TD]HTMLDoc.all.Email.Value = "Infousername"[/TD]
[/TR]
[TR]
[TD]HTMLDoc.all.password.Value = "Info password"[/TD]
[/TR]
[TR]
[TD]For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")[/TD]
[/TR]
[TR]
[TD]If MyHTML_Element.Type = "submit" Then MyHTML_Element.Click: Exit For[/TD]
[/TR]
[TR]
[TD]Next[/TD]
[/TR]
[TR]
[TD]Err_Clear:[/TD]
[/TR]
[TR]
[TD]If Err <> 0 Then[/TD]
[/TR]
[TR]
[TD]Err.Clear[/TD]
[/TR]
[TR]
[TD]Resume Next[/TD]
[/TR]
[TR]
[TD]End If[/TD]
[/TR]
[TR]
[TD]End Sub[/TD]
[/TR]
</tbody>[/TABLE]

i have also tried this

Code:
[TABLE="width: 705"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Sub Test_LoginXXX()
[/TD]
[/TR]
[TR]
[TD]LoginXXX"kmail", "kPassword"[/TD]
[/TR]
[TR]
[TD]End Sub[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Sub LoginXXX(email As String, password As String)[/TD]
[/TR]
[TR]
[TD]Const strURL_c As String = "https://www.xxx.com"[/TD]
[/TR]
[TR]
[TD]Dim url As String[/TD]
[/TR]
[TR]
[TD]Dim objIE As SHDocVw.InternetExplorer[/TD]
[/TR]
[TR]
[TD]Dim ieDoc As MSHTML.HTMLDocument[/TD]
[/TR]
[TR]
[TD]Dim tbxPwdFld As MSHTML.HTMLInputElement[/TD]
[/TR]
[TR]
[TD]Dim tbxUsrFld As MSHTML.HTMLInputElement[/TD]
[/TR]
[TR]
[TD]Dim btnSubmit As MSHTML.HTMLInputElement[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Excel.Application.Cursor = xlWait[/TD]
[/TR]
[TR]
[TD]On Error GoTo Err_Hnd[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Set objIE = New SHDocVw.InternetExplorer[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]objIE.navigate strURL_c[/TD]
[/TR]
[TR]
[TD]objIE.Visible = True[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Do Until objIE.readyState = READYSTATE_COMPLETE: Loop[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Set ieDoc = objIE.document[/TD]
[/TR]
[TR]
[TD]Application.Wait Now + TimeValue("00:00:05")[/TD]
[/TR]
[TR]
[TD]ieDoc.getElementsByName("email").Item(0).Value = PIN[/TD]
[/TR]
[TR]
[TD]ieDoc.getElementById("password").Value = Password[/TD]
[/TR]
[TR]
[TD]ieDoc.getElementsByClassName("btn btn-primary btn-med ladda-button").Item(0).Click[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Err_Hnd:[/TD]
[/TR]
[TR]
[TD]objIE.Visible = True[/TD]
[/TR]
[TR]
[TD]On Error GoTo 0[/TD]
[/TR]
[TR]
[TD]Excel.Application.Cursor = xlDefault[/TD]
[/TR]
[TR]
[TD]End Sub
[/TD]
[/TR]
</tbody>[/TABLE]


The result is still that i get no information in the login and password fields

Can anyone pls help on this?!?!

The ID on this is "pf.username" maybe this has something to do with it, i am at a lossas to what i can do
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Does anyone have a clue as to why this wouldn't work??!?! i am still stuck on this
 
Upvote 0
Without knowing the URL, which you haven't supplied, I can only guess.

The ID on this is "pf.username" maybe this has something to do with it, i am at a lossas to what i can do
Try:
Code:
ieDoc.getElementById("pf.username").Value = "your username"
 
Upvote 0
Unfortunately i can't send the link on the forum.

I have tried what you suggest through the second try and i couldn't get it to work.

If there is a way to reply to you in private i could send the URL on to you, if you wish.

But many thanks for replying any help is really appreciated.
 
Last edited:
Upvote 0
You're mistaken in that the element has the name "pf.username", not the id.

HTML:
< input class="form-control input-lg required" tabindex="1" size="36" autocorrect="off" autocapitalize="off" name="pf.username"
    value="" placeholder="Work email / username" type="text" >

Therefore try:

Code:
ieDoc.getElementsByName("pf.username")(0).Value = "your username"
 
Upvote 0

Forum statistics

Threads
1,215,473
Messages
6,125,022
Members
449,203
Latest member
tungnmqn90

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