VBA Login direct to Website adding PIN and Password automatically

Crool

New Member
Joined
Jul 7, 2010
Messages
12
Hi,

I have been updating a simple access code I use in VBA (below)

Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Sub MyReece()

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

<tbody>
</tbody>

This works to a point as i am accessing newer web pages and it is not placing the PIN and Password i have in the Macro, so i am trying to use this newer version, but i am getting the same result no PIN or Password.

Sub Test_LoginXXX()
LoginReece "kEmail", "kPassword"
End Sub
' Add references in Tools > References for:
' Microsoft HTML Object Library
' Microsoft Forms 2.0 Object Library
' Microsoft Internet Controls
Sub LoginXXX(email As String, password As String)
Const strURL_c As String = "https://www.xxx.com"
Dim url As String
Dim objIE As SHDocVw.InternetExplorer
Dim ieDoc As MSHTML.HTMLDocument
Dim tbxPwdFld As MSHTML.HTMLInputElement
Dim tbxUsrFld As MSHTML.HTMLInputElement
Dim btnSubmit As MSHTML.HTMLInputElement
Excel.Application.Cursor = xlWait
On Error GoTo Err_Hnd
'Create Internet Explorer Object
Set objIE = New SHDocVw.InternetExplorer
'Navigate the URL
objIE.navigate strURL_c
objIE.Visible = True
'Wait for page to load
'https://msdn.microsoft.com/en-us/library/ms534361(v=vs.85).aspx
Do Until objIE.readyState = READYSTATE_COMPLETE: Loop
'Do: Loop Until objIE.readyState = READYSTATE_COMPLETE
Set ieDoc = objIE.document
Application.Wait Now + TimeValue("00:00:05")
ieDoc.getElementsByName("email").Item(0).Value = PIN
ieDoc.getElementById("password").Value = Password
ieDoc.getElementsByClassName("btn btn-primary btn-med ladda-button").Item(0).Click
Err_Hnd: '(Fail gracefully)
objIE.Visible = True
On Error GoTo 0
Excel.Application.Cursor = xlDefault
End Sub

<tbody>
</tbody>

I need help to get this solved because in the new pages, the ID is "pf.username" so i can't use the first code effectively.

Any help would be really appreciated.
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,215,758
Messages
6,126,702
Members
449,331
Latest member
smckenzie2016

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