EXCEL VBA HTTP - Problem logging in to bank account

NikolaJovanovic

New Member
Joined
Jan 31, 2016
Messages
24
Good evening to all,

I have been struggling since last week with this.
The purpose of the macro is to automatically sign in, get the Statement, and proceed to the next account, gets the statement, signs out, goes to another Bank...and so on.
But I can not even program it to log in.

I get the run-time error '91':
Object Variable or With block variable not set

The code stops at:
Code:
html.getElementById("ctl00_ctl00_Utilizador").Value = "itsme"
without input.

I can not figure out why.
Could somebody please help me..

I have these References checked.

Visual Basic For Application
Microsoft Excel 14.0 Object Library
OLE Automation
Microsoft Office 14,0 Object Library
Microsoft HTML Object Library
Microsoft Internet Controls
Microsoft Forms 2.0 Object Library

Code:
Sub LogIn()

Dim ie As InternetExplorer
Dim html As HTMLDocument

Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "https://emp.bancobai.ao/"

Do While ie.ReadyState <> READYSTATE_COMPLETE
Application.StatusBar = "Trying to go to StackOverflow ..."
DoEvents
Loop

Set html = ie.Document
html.getElementById("ctl00_ctl00_Utilizador").Value = "itsme"
html.getElementById("ctl00_ctl00_Password").Value = "123"

End Sub

P.S. You can see the http when you load the page.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I just remembered.
Password!!! Since it can not just be done with a keyboard, I planned to make a code that examines the value of each place on screen keyboard and if true with the character of the password then click, end so on for each character of the password.
 
Upvote 0

Let me be pessimistic...
To cope with the security of the Teclado Virtual you need to read the "InnerHtml" of elements id="btnkey0" to id="btnkey35"; parse all of them and get the corresponding "Value"; then click the IDs that corresponds to your password and finally click id="ctl00_ctl00_SubmitBtn"

Then my guess is that the security checks at the bank will take 10 milliseconds to understand that a robot is trying to type passwords and will close the connection, or lock remote access to the bank account.

Anyway, probably you can collect the values of each of the btnkey using this code:

Code:
Sub BankAcc()
Dim IE As Object
Dim myDoc, myF, myBtn(0 To 35, 0 To 1), mySplit, myVal As String

myURL = "https://emp.bancobai.ao/"
If IE Is Nothing Then Set IE = CreateObject("InternetExplorer.Application")
With IE
    .Navigate myURL
    .Visible = True
    Do While .Busy: DoEvents: Loop    'Attesa not busy
    Do While .ReadyState <> 4: DoEvents: Loop 'Attesa documento
End With

myStart = Timer
Do  '1 sec prudenziale
    DoEvents
    If Timer > myStart + 1 Or Timer < myStart Then Exit Do
Loop

Set myDoc = IE.Document
Set myF = myDoc.getelementsbytagname("iframe")

myF(0).getElementbyId("ctl00_ctl00_Utilizador").Value = "itsme"

For i = 0 To 35
    mySplit = Split(myF(0).getElementbyId("btnkey" & i).innerhtml & " ", "Value=", , vbTextCompare)
    If UBound(mySplit, 1) = 1 Then
        myVal = Trim(Replace(Left(mySplit(1), 4), """", "", , , vbTextCompare))
        myBtn(i, 0) = myVal
        myBtn(i, 1) = "btnkey" & i
    End If
Next i
'...

Then you have to scan your password character by character, and determine in which position of the array myBtn it is located; than you can click that btn using
'to click a btn:
Code:
myF(0).getElementbyId(myBtn(i, 1)).Click     'myBtn(i, 1) contains the name of the btn
Finally you may click Entrar:
Code:
myF(0).getElementbyId("ctl00_ctl00_SubmitBtn").Click
HOWEVER my installed Internet Explored 11 do not support IFrames and therefore I was not able to test other then the navigation to the site; after I get a sad " O seu browser não suporta iframes."

I hope you will be able to get more....

Of course this is only the beginning, ie you get logged: then you have to examine the html code of your next page and determine how coding your next commands...

Bye
 
Last edited:
Upvote 0
Thank for the reply Anthony47.

Ok.
Let me concentrate first on username entry.

So I copied your code.

The line:
Code:
[COLOR=#333333]Set myF = myDoc.getelementsbytagname("iframe")[/COLOR]
might not be recognized. If it was it would be like:
Code:
.getElementsByTagName
Maybe I am making a mistake somewhere.
When you run it, does the code gets the username into the "Value" ("itsme") of the field ("id")?
 
Upvote 0
As I said, I.E. 11 installed in my computer seems do not support IFrames; I normally use Chrome so am not willing install different versions of IE.

Getelementsbytagname and getElementsByTagName is the same keyword.

You cannot just copy one line, you have to use all the code I listed.

Bye
 
Upvote 0
I copied the whole code.
It still gets an error on
Code:
myF(0).getElementbyId("ctl00_ctl00_Utilizador").Value = "itsme"
.
I am trying to find a solution with iFrame.
If I could ask you just one question more.
So, if I got it right, it is something like I need to get iFrame and after that get the elementId of "ctl00_ctl00_Utilizador"?
If it's correct, what could be the reason for the code not to work?

Thank you very much, for the insight.
bye
 
Upvote 0
I missed the notification of your message, sorry.

In the meantime I understood how setting IE to cope with iframes and was able to test more, and indeed it was more complex than I had in mind.
With the following code IT SEEMS that I was able to submit my login credentials
Code:
Sub BankAcc2()
Dim IE As Object
Dim myDoc, myF, myBtn(0 To 35, 0 To 1), mySplit, myVal As String

Dim myB As Object, myIB As Object, myPIP As Object, myINP   '''

myURL = "https://emp.bancobai.ao/"
If IE Is Nothing Then Set IE = CreateObject("InternetExplorer.Application")
With IE
    .navigate myURL
    .Visible = True
    Do While .Busy: DoEvents: Loop    'Attesa not busy                       '***
    Do While .readyState <> 4: DoEvents: Loop 'Attesa documento     '***
End With

myStart = Timer
Do  '1 more sec 
    DoEvents
    If Timer > myStart + 1 Or Timer < myStart Then Exit Do
Loop

Set myDoc = IE.document

Set myF = myDoc.getElementsByTagName("iframe")
Set myIB = IE.document.getElementsByTagName("iframe")(0).contentDocument.getElementsByTagName("body")(0)
'
Set myPIP = myIB.getElementsByTagName("input")
For Each myINP In myPIP
    If myINP.Name = "ctl00$ctl00$Utilizador" Then
'        Stop
        myINP.Value = "Itsme"
    End If
'HERE:
'CHECK FOR INPUT ctl00$ctl00$Password TO BE FILLED and ctl00$ctl00$SubmitBtn TO BE CLICKED
'
Next myINP
'
'here you'll need to synch with the browser busy status and DocumentComplete status
'(see the two lines marked ***)
' then you can read your next html page and...
'
End Sub
And it was even not necessary using the virtual keyboard to load the password!?
Of course my login request was rejected, but maybe your credentials will have more chances.

HOWEVER this code is a small step (not a giant leap) toward accessing a banking server, even though I am sure that as soon as the server realizes that the connection is not driven by a human but by a robot it will close the connection.
I am not sure how legal this is. Therefore I shall not provide any further help. Sorry

Bye
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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