Sunday, December 24, 2017

VBA Excel for Login



Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer


Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _
            (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2


===============


Dim MyURL As String
 On Error GoTo Err_Clear
 MyURL = "https://infinity.icicibank.com/corp/AuthenticationController?FORMSGROUP_ID__=AuthenticationFG&__START_TRAN_FLAG__=Y&FG_BUTTONS__=LOAD&ACTION.LOAD=Y&AuthenticationFG.LOGIN_FLAG=1&BANK_ID=ICI"
 Set MyBrowser = New InternetExplorer
 MyBrowser.Silent = True
 MyBrowser.navigate MyURL
 apiShowWindow MyBrowser.hwnd, SW_MAXIMIZE
 MyBrowser.Visible = True
 Do
 Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
 Set HTMLDoc = MyBrowser.document
 'HTMLDoc.all.CorporateSignonCorpId.Value = "" 'Enter your email id here
 'HTMLDoc.all.CorporateSignonPassword.Value = "" 'Enter your password here

 For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")
 If MyHTML_Element.ID = "AuthenticationFG.USER_PRINCIPAL" Then MyHTML_Element.Value = "ICICIUSERID": Exit For
 Next


 For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")
 If MyHTML_Element.ID = "AuthenticationFG.ACCESS_CODE" Then MyHTML_Element.Value = "ICICICPASSWORD": Exit For
 Next

 For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")
 If MyHTML_Element.ID = "VALIDATE_CREDENTIALS1" Then MyHTML_Element.Click: Exit For
 Next

 Application.Wait Now + TimeValue("00:00:10")

 For Each MyHTML_Element In HTMLDoc.getElementsByTagName("a")
 If MyHTML_Element.ID = "Bank-Accounts" Then MyHTML_Element.Click: Exit For
 Next


 For Each MyHTML_Element In HTMLDoc.getElementsByTagName("a")
 If MyHTML_Element.ID = "HREF_actNicNameOutput[0]" Then accName = MyHTML_Element.Value: Exit For
 Next

 For Each MyHTML_Element In HTMLDoc.getElementsByTagName("a")
 If MyHTML_Element.ID = "HREF_actNoOutput[0]" Then AccNo = MyHTML_Element.Value: Exit For
 Next

 For Each MyHTML_Element In HTMLDoc.getElementsByTagName("a")
 If MyHTML_Element.ID = "HREF_actBalOutput[0]" Then AccBal = MyHTML_Element.Value: Exit For
 Next


Err_Clear:
 If Err <> 0 Then
 Err.Clear
 Resume Next
 End If