HTML controls problems on a web page with VBA

Asked

Viewed 236 times

0

I am trying to fill the controls on a web page with an interaction between VBA and IE, I am not able to find and popular the fields related to the date of validity of the minutes.

inserir a descrição da imagem aqui

URL Of Page: http://comprasnet.gov.br/aceso.asp?url=/Livre/Ata/Consultaata00.Asp

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
  • people found that the tags in question are inside a frame called main2

  • if you found it useful to vote for the answer! rs

1 answer

0


the error was happening because the tags were inside a Frame, the solution was 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.