HTML controls problems on a web page with VBA

0

I'm trying to fill in the controls on a web page with an interaction between VBA and IE, I'm not able to find and popular the fields referring to the effective date of the minutes.

PageURL: link

VBA code:

Sub x()
    Dim ie As InternetExplorer
    Dim C
    Dim ULogin As Boolean, ieForm
    Dim MyPass As String, MyLogin As String

    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "http://comprasnet.gov.br/acesso.asp?url=/Livre/Ata/ConsultaAta00.asp"

    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop


    ie.Document.getElementsByName("dt_ini").Value = "12/12/2012" 'o erro ocorre aqui
    ie.Document.getElementsByName("dt_fim").Value = "12/11/2011" 'o erro ocorre aqui

End Sub

Sub Referencia()
    Dim ObRef
    On Error Resume Next
    ' Adiciona Controles da Net
    ThisWorkbook.VBProject.References.AddFromGuid "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 1, 1
End Sub
    
asked by anonymous 22.11.2016 / 19:28

1 answer

0

The error was happening because the tags were inside a Frame, the solution looked like this:

Sub x()
    Dim ie As InternetExplorer
    Dim objCollection
    Dim ULogin As Boolean, ieForm
    Dim MyPass As String, MyLogin As String

    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "http://comprasnet.gov.br/acesso.asp?url=/Livre/Ata/ConsultaAta00.asp"

    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop

    Set objCollection = ie.Document.frames(1).Document.getElementsByTagName("input")

    i = 0



    Do While i < objCollection.Length
        If objCollection(i).Name = "dt_ini" Then
            objCollection(i).Value = "12/12/2015"
        End If

        If objCollection(i).Name = "dt_fim" Then
            objCollection(i).Value = "11/12/2016"
        End If
        i = i + 1
    Loop


End Sub

Sub Referencia()
    Dim ObRef
    On Error Resume Next
    ' Adiciona Controles da Net
    ThisWorkbook.VBProject.References.AddFromGuid "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 1, 1
End Sub
    
25.11.2016 / 15:47