VBA loggin into a website

Ograda

New Member
Joined
Mar 7, 2014
Messages
7
Hello guys, first i'm in need of a code that logs in into an website to collect it's information.
I've been trying it in a hole different ways, but none seems to work, i've tryed many codes and kinds, i've seen some problems that i'd not been able to solve.

First of all:
The website never gets ready (readystate 4 never occurs)

Second problem:
if i put a loop waiting for busy ends or readystate 4, it throws me out of the execution.

Third problem:
I got some problems refeering the cells that i need to fill in HTML document.

well, here goes the HTML code:
HTML:
<body ******="form2.elements[0].focus()" >    
<div id="box_login">        
<div class="td1Titulo">Identificação</div>        
<div class="td1fundoclaro">            
<div id="mensagem_erro"></div><br />            
<form name="form2" id="form_login" method="post" action="testa_login.asp">                
<div class="login_info">                    Preencha os campos para acessar a área restrita                 </div><br />                
<div class="login_info left">                    
<div class="label_50"><label for="txtUsuario">Login: </label></div>                    
<input type="text" name="txtUsuario" size="10" class="botao required">                </div>                
<div class="login_info left">                    
<div class="label_50"><label for="password">Senha: </label></div>                    
<input type="password" name="txtSenha" size="10" class="botao required">                </div>                
<div class="login_info">                    
<input type="submit" name="Entrar" value=" Entrar " class="botao">                    
<input type="reset" name="Limpar" value="Limpar" class="botao">                
</div>                
<div class="login_info">                    <br /> Não sabe ou esqueceu sua senha? <br />                    
<a href="http://intranet.ad.finep.gov.br/gerenciador/Senha/senha.asp">Clique aqui</a>                     para gerar uma nova e recebê-la por correio eletrônico. <br /><br />                    Para alterar sua senha da intranet:                     
<a href="http://intranet.ad.finep.gov.br/gerenciador/Senha/troca_senha.asp">Alterar                   senha</a><br /><br />                   
<a href="javascript:history.back()" class="rodape">Voltar</a>                
</div>              
</form>        
</div>    
</div>
</body>

i need to fill this forms:
HTML:
then click this button:
[HTML]<input type="submit" name="Entrar" value=" Entrar " class="botao">

i'm using this code at moment, it loads the website, and then stops, i couldn't get further on any other VBA code.

Code:
Sub getValues()Dim objIe As Object, xobj As HTMLDivElement


    Set objIe = CreateObject("InternetExplorer.Application")
    objIe.Visible = True


    objIe.Navigate "http://intranet." 'website


   ' While (objIe.Busy Or objIe.ReadyState <> 4): DoEvents: Wend  ' if i cut of this comment and executs the code until here, it gets me the problem 1


    Set xobj = objIe.Document.getElementById("box_login")
' executing the code without checking for its readystate, returns me error on the line above (problem 2)
    'Set xobj = xobj.getElementsByClassName("login_info").Item(0)
    'Set xobj = xobj.getElementsByClassName("data")(0)


    Debug.Print xobj.innerText


    Set xobj = Nothing


    objIe.Quit
    Set objIe = Nothing
End Sub

the problem 1 is:
"automation error"
"not specifyed error" (translating myself, my Excell is on brazilian portuguese)

the problem 2 is:
"automation error"
"not specifyed error" (translating myself, my Excell is on brazilian portuguese)
 
Also, have you tried navigating to that site manually to make sure everything's working there?
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
i did, i'd made a couple changes at the code and i've putted it to work yesterday but i got a new problem today idk why again, thats getting me crazy hahaha

the code used today with some sort of modification is:
Code:
Set objIe = New InternetExplorer    objIe.Visible = True
    objIe.Navigate "http://intranet.*"
    While (objIe.Busy): DoEvents: Wend
    
    testUrl = cutFromEnd(objIe.LocationURL, "/")
    If testUrl = "login.asp" Then


        Set Elements = objIe.Document.getElementsByTagName("input")
        For Each inputs In Elements
            str = inputs.getAttribute("name")
            If str = "txtUsuario" Then
                inputs.innerText = user
            End If
            If str = "txtSenha" Then
                inputs.innerText = senha
            End If
            If str = "Entrar" Then
                inputs.Click
                Exit For
            End If
        Next inputs
    Else
        Debug.Print "logged in"
    End If

the modifications are working well i guess, its just a test to check if the system needs to login or if its already logged in, if it finds "login.asp" in browser URL then it start the process for logging in, nothing at all..

trying to execute this code i receive error in this line:
Code:
Set Elements = objIe.Document.getElementsByTagName("input")
The reported error is:
the 'document' method of 'IWebBrowser2' has failed

i've noted that the html code of my webpage is daily changing, but notting on it structural part, some ids changes and this kind of stuff, thats why i've changed the document to look for "inputs" instead of getting "ids".

i'm really kind of lost now, got no idea of why the method is failing.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,053
Members
449,206
Latest member
Healthydogs

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