This code clicks on the 'Legislation' tab fills a field with a specific text (2nd For Each) and clicks the search button (3rd For Each). The problem is that when I run the code, it clicks on the tab and fills in the text, but it zeroes the field before doing the search, and I tried it in two different ways. What should I do?
'Declara função Sleep
If VBA7 Then
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
Else
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
End If
Sub CDE_ANEEL()
Dim IE As Object
Dim doc As Object, doc1 As Object, doc2 As Object, aba As Object
Dim sFilename As String, sFilepath As String
Dim objStream As Object
Dim strData As String
Dim el
Set objStream = CreateObject("ADODB.Stream")
sFilename = "CDE.txt"
sFilepath = "C:\Users\leandro.lazari\Desktop\Dados MegaWhat\Dados" & "\" & sFilename
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "http://biblioteca.aneel.gov.br/index.html"
IE.Visible = True
Sleep 2000
Set doc = IE.document.getElementsByTagName("frame")(0).contentDocument.body
Set doc1 = doc.getElementsByClassName("inputLegEsq")
Set doc2 = doc.getElementsByClassName("button_busca")
Set aba = doc.getElementsByClassName("text-aba")
'clica em aba 'Legislação'
For Each el In aba
'Debug.Print el.InnerText
If el.innerText = "Legislação" Then el.Click
Next el
'preenche campo: 'Todos os Campos'
For Each el In doc1
'Debug.Print el.Name, el.Value
If el.Name = "leg_campo1" Then el.Value = "Conta de Desenvolvimento Energético"
Next el
'Apertar Botão
For Each el In doc2
Debug.Print el.Title, el.onclick
Debug.Print InStr(1, el.onclick, "Confere(5613,5,'',parent.hiddenFrame.modo_busca)")
If InStr(1, el.onclick, "Confere(5613,5,'',parent.hiddenFrame.modo_busca)") > 0 Then el.Click
Next el
' Apertar o Botão de outra forma
For Each el In doc2
If InStr(1, el.onclick, "Confere(5613,5,'',parent.hiddenFrame.modo_busca)") > 0 Then el.Click
Next el
End Sub