Sub IE_WebPageLogOn()
Dim AC_Code As String
Dim AC_Name As String
Dim i As Long
Dim LogOn_ID As String
Dim LogOn_URL As String
Dim objIE As Object
Dim ObjCollection As Object
Dim Passcode As String
Dim RegNo As String
Dim WshShell
‘Closes all IE sessions.
Call IE_Sledgehammer
Set objIE = CreateObject("InternetExplorer.Application")
AC_Code = Range("LogOn_SheetName").Value
LogOn_ID = Range("LogOn_LogOnID").Value
LogOn_URL = Range("LogOn_URL").Value
'LogOn_URL = "https://retail.santander.co.uk/LOGSUK_NS_ENS/BtoChannelDriver.ssobto?dse_operationName=LOGON&dse_processorState=initial&redirect=S"
'Load Santander.com
With objIE
.Visible = True
.Navigate LogOn_URL
.Visible = True
End With
'>>>Inputs the User ID.
'WAIT TO LOAD – The un-commented script is what I am using in this section
'Application.Wait Now + TimeValue("00:00:03")
'XXX
Do Until Not objIE.Busy And objIE.ReadyState = 4
DoEvents
Loop
'XXX
'While objIE.Busy Or objIE.ReadyState <> 4: DoEvents: Wend
'XXX
'While objIE.ReadyState <> READYSTATE_COMPLETE And objIE.ReadyState <> READYSTATE_LOADED
'DoEvents
'Wend
objIE.Document.getElementsByName("infoLDAP_E.customerID")(0).Value = LogOn_ID
SendKeys ("{TAB}")
SendKeys ("{ENTER}")
'>>>Turns 'Number Lock' back On.
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "{NUMLOCK}"
'>>>Inputs the Passcode.
'WAIT TO LOAD – The un-commented script is what I am using in this section
Application.Wait Now + TimeValue("00:00:06")
'XXX
'Do Until Not objIE.Busy And objIE.ReadyState = 4
'DoEvents
'Loop
'XXX
'While objIE.Busy Or objIE.ReadyState <> 4: DoEvents: Wend
'XXX
'While objIE.ReadyState <> READYSTATE_COMPLETE And objIE.ReadyState <> READYSTATE_LOADED
'DoEvents
'Wend
objIE.Document.getElementsByName("authentication.PassCode")(0).Value = Passcode
'>>>Inputs the Registration Number and Enters through to main page.
objIE.Document.getElementsByName("authentication.ERN")(0).Value = RegNo
objIE.Document.getElementsByName("buttons.1")(0).Click
'>>>Selects the account to review.
'WAIT TO LOAD – The un-commented script is what I am using in this section
Application.Wait Now + TimeValue("00:00:04")
'XXX
'Do Until Not objIE.Busy And objIE.ReadyState = 4
'DoEvents
'Loop
'XXX
'While objIE.Busy Or objIE.ReadyState <> 4: DoEvents: Wend
'XXX
'While objIE.ReadyState <> READYSTATE_COMPLETE And objIE.ReadyState <> READYSTATE_LOADED
'DoEvents
'Wend
'>>>From Mr Excel...John...
Dim HTMLdoc As HTMLDocument
Dim link As HTMLAnchorElement
'Dim i As Long
'>>>Accounts page has loaded, identify the Hyperlink for the appropriate account to be interrogated and Click.
Set HTMLdoc = objIE.Document
Set link = Nothing
i = 0
While i < HTMLdoc.Links.Length And link Is Nothing
If HTMLdoc.Links(i).innerText = AC_Code Then Set link = HTMLdoc.Links(i)
i = i + 1
Wend
If Not link Is Nothing Then
link.Click
'WAIT TO LOAD – The un-commented script is what I am using in this section
Application.Wait Now + TimeValue("00:00:04")
'XXX
'Do Until Not objIE.Busy And objIE.ReadyState = 4
'DoEvents
'Loop
'XXX
'While objIE.Busy Or objIE.ReadyState <> 4: DoEvents: Wend
'XXX
'While objIE.ReadyState <> READYSTATE_COMPLETE And objIE.ReadyState <> READYSTATE_LOADED
'DoEvents
'Wend
Else
MsgBox "Link not found"
End If
'>>>Transactions page loaded, then appropriate dates to be input.
'WAIT TO LOAD – The un-commented script is what I am using in this section
Application.Wait Now + TimeValue("00:00:06")
'XXX
'Do Until Not objIE.Busy And objIE.ReadyState = 4
'DoEvents
'Loop
'XXX
'While objIE.Busy Or objIE.ReadyState <> 4: DoEvents: Wend
'XXX
'While objIE.ReadyState <> READYSTATE_COMPLETE And objIE.ReadyState <> READYSTATE_LOADED
'DoEvents
'Wend
'>>>On same page, input the From and To dates and then Click the 'Search' button (last bit isn't working yet)..
'objIE.Document.getElementsByName("searchForm.fromDate.day")(0).Value = 1
'objIE.Document.getElementsByName("searchForm.fromDate.month")(0).Value = 2
'objIE.Document.getElementsByName("searchForm.fromDate.year")(0).Value = 2019
'
'objIE.Document.getElementsByName("searchForm.toDate.day")(0).Value = "1"
'objIE.Document.getElementsByName("searchForm.toDate.month")(0).Value = "3"
'objIE.Document.getElementsByName("searchForm.toDate.year")(0).Value = "2019"
'
'objIE.Document.getElementsByClassName("button")(0).Click
'>>>On same page, identify the Hyperlink for 'Download transactions' and Click.
Set HTMLdoc = objIE.Document
Set link = Nothing
i = 0
While i < HTMLdoc.Links.Length And link Is Nothing
If HTMLdoc.Links(i).innerText = "Download transactions" Then Set link = HTMLdoc.Links(i)
i = i + 1
Wend
If Not link Is Nothing Then
link.Click
' While objIE.Busy Or objIE.ReadyState <> 4: DoEvents: Wend
Else
MsgBox "Link not found"
End If
'WAIT TO LOAD – The un-commented script is what I am using in this section
Application.Wait Now + TimeValue("00:00:06")
'XXX
'Do Until Not objIE.Busy And objIE.ReadyState = 4
'DoEvents
'Loop
'XXX
'While objIE.Busy Or objIE.ReadyState <> 4: DoEvents: Wend
'XXX
'While objIE.ReadyState <> READYSTATE_COMPLETE And objIE.ReadyState <> READYSTATE_LOADED
'DoEvents
'Wend
'>>>Select Download To option as 'Microsoft Excel (XLS)'.
'objIE.Document.getElementsByName("downloadStatementsForm.typeFile")(0).selectedIndex = 1
With objIE.Document.getElementsByName("downloadStatementsForm.typeFile")(0)
.selectedIndex = 1
.FireEvent "onchange"
End With
'objIE.Document.getElementsByName("downloadStatementsForm.typeFile")(0).Value = "Microsoft Excel (XLS)"
'SendKeys ("{TAB}")
'SendKeys ("{ENTER}")
'WAIT TO LOAD – The un-commented script is what I am using in this section
'Application.Wait Now + TimeValue("00:00:04")
Do Until Not objIE.Busy And objIE.ReadyState = 4
DoEvents
Loop
'XXX
'While objIE.Busy Or objIE.ReadyState <> 4: DoEvents: Wend
'XXX
'While objIE.ReadyState <> READYSTATE_COMPLETE And objIE.ReadyState <> READYSTATE_LOADED
'DoEvents
'Wend
'>>>On same page, input the From and To dates to be downloaded.
objIE.Document.getElementsByName("downloadStatementsForm.fromDate.day")(0).Value = "1"
objIE.Document.getElementsByName("downloadStatementsForm.fromDate.month")(0).Value = "2"
objIE.Document.getElementsByName("downloadStatementsForm.fromDate.year")(0).Value = "2019"
objIE.Document.getElementsByName("downloadStatementsForm.fromDate.day")(0).Value = "1"
objIE.Document.getElementsByName("downloadStatementsForm.fromDate.month")(0).Value = "3"
objIE.Document.getElementsByName("downloadStatementsForm.fromDate.year")(0).Value = "2019"
'>>>On same page, Click the 'Download' button.
objIE.Document.getElementsByName("downloadStatementsForm.events.0")(0).Click
End Sub