How to read a IE table text with VBA?

后端 未结 1 1624
说谎
说谎 2021-01-01 07:52

I am trying to write a vba code in order to follow this process:

  1. Automatic Web form fill in and submitting (a new web page opens with the answer http://ec.e

相关标签:
1条回答
  • 2021-01-01 08:25

    Try this

    Sub getData()
    
    '~~~~Variable declaration~~~~'
        Dim IE As Object
        Dim country As Object
        Dim num As Object
        Dim btn As Object
        Dim tlb As Object, td As Object
    
        Set IE = CreateObject("InternetExplorer.Application")
    
        IE.Visible = False
        IE.navigate "http://ec.europa.eu/taxation_customs/vies/?locale=en"
    
    'Wait till page is loaded
        Do While IE.readystate <> 4
            DoEvents
        Loop
    
    
        Set country = IE.document.getelementbyid("countryCombobox")
        country.Value = "FR" 'set the value for Member state
    
    
    'Pause the code for 5 sec
        Application.Wait Now + TimeSerial(0, 0, 5)
    
    '
        Set num = IE.document.getelementbyid("number")
        num.Value = "27435044714" 'set the Vat number
    
    
        Application.Wait Now + TimeSerial(0, 0, 5)
    
    
        Set btn = IE.document.getelementbyid("submit")
        btn.Click ' click the verify button
    
    'Wait till page is loaded
        Do While IE.readystate <> 4: DoEvents: Loop
    
    'Pause the code for 5 sec
            Application.Wait Now + TimeSerial(0, 0, 10)
    
            Set tbl = IE.document.getelementbyid("vatResponseFormTable")
    
            For Each td In tbl.getelementsbytagname("td")
                If td.innerText = "Name" Then
                    MsgBox "Name : " & td.NextSibling.innerText
                ElseIf td.innerText = "Address" Then
                    MsgBox "Address : " & td.NextSibling.innerText
                ElseIf td.innerText = "Consultation Number" Then
                    MsgBox "Consultation Number : " & td.NextSibling.innerText
                End If
    
            Next
    
    
            IE.Quit
            Set IE = Nothing
     End Sub
    
    0 讨论(0)
提交回复
热议问题