• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Internet Automation

ARTHUR WESLEY

New Member
Hello,

I want to automate the generation of a specific pdf by the following url:

hhttp://consulta.tesouro.fazenda.gov.br/gru_novosite/gru_simples.asp


My aim is to fill all site fields through a macro.

I could already fill the UG. But I can not fill the Gestão, which is an DropDown.

Follows the code in VBA I am using:

Code:
Sub GRU_STN()

Dim ie As InternetExplorer
   
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "https://consulta.tesouro.fazenda.gov.br/gru_novosite/gru_simples.asp"

Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
   
'The UG FILLING:
 ie.Document.all.Item("frm").Item("codigo_favorecido").innerText = "010001"
 ie.Document.forms.Item("frm").Item(0).onchange
   
 'The GESTÃO FILLING: (THIS IS NOT WORKING):
 ie.Document.getElementById("gestao").Focus
 ie.Document.getElementById("gestao").selectedIndex = 1
 ie.Document.getElementById("gestao").FireEvent ("onchange")

End Sub

I am filling the UG with "010001". I would like to select the following option in Gestão: "00001-TESOURO NACIONAL".

I do not know if I was clear.

If you could give me a hand I would appreciate it greatly. I have been there more than a week of it and nothing ...

Attached is my Excel spreadsheet.

Thank U!
 

Attachments

  • VBA_GRU_STN_HELP.xlsm
    17.3 KB · Views: 5

Hi,

wild cross posting !
So without a link for each other forum where same question was posted …

Here is formula Excel forum, move to VBA Macros

All I can tell is you must synchronize VBA with IE after each element
update (wait a second); automating IE is often the slowest and
more erratic way, the better is a request like webbrowser does …
 
Hi

as Marc suggests you need to give wait time after each filling. As the dropdown takes values and processes the next field based on onchange event. This will not get captured by ie.readystate.

Regards,
Prasad DN
PS: i check your code by running line by line F8 mode and it works perfectly.
 
Thank you guys.

Really I should wait a time after each filling.

I used the following code and it worked:

Code:
Sub GRU_STN()
    Dim ie As InternetExplorer
  
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "https://consulta.tesouro.fazenda.gov.br/gru_novosite/gru_simples.asp"

    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop
  
  
    ie.Document.all.Item("frm").Item("codigo_favorecido").innerText = "010001"
    ie.Document.forms.Item("frm").Item(0).onchange
  
  
    Call FnWait(1)
    ie.Document.getElementById("gestao").selectedIndex = 1
  
  
  
    ie.Document.getElementById("gestao").FireEvent ("onchange")
  
  
End Sub

Function FnWait(intTime)

    newHour = Hour(Now())

    newMinute = Minute(Now())

    newSecond = Second(Now()) + intTime

    waitTime = TimeSerial(newHour, newMinute, newSecond)

    Application.Wait waitTime

End Function

;)
 

Wait don't need a function, just see the sample in its inner VBA help !

I won't be surprised if you code fails sometimes …
 
Ok, now without a function:

Code:
Sub GRU_STN()
    Dim ie As InternetExplorer
  
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "https://consulta.tesouro.fazenda.gov.br/gru_novosite/gru_simples.asp"

    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop
  
    ie.Document.all.Item("frm").Item("codigo_favorecido").innerText = "010001"
    ie.Document.forms.Item("frm").Item(0).onchange
  
    Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 1)
    
    ie.Document.getElementById("gestao").selectedIndex = 1
  
    ie.Document.getElementById("gestao").FireEvent ("onchange")
  
  
  
End Sub

Thanks!
 
Back
Top