Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
161 views
in Technique[技术] by (71.8m points)

Using VBA to extract information from Internet explorer - I'm stuck

I designed some code a while ago using VBA and Excel, to check which people on my database are still VAT registered. I'm based in the UK, and I was using a European website, but because of Brexit it's no longer working! I changed it to a British website now, and I managed to get the code to enter the VAT number from Excel into the webpage, but I can't find the Id or name of the submit button, so I'm not able to submit it. After I've submitted it I'll probably need some more help, but I'll see if anyone can help me solve this one first. Many thanks for your help. Here's the code.

Sub CheckVatPlayers()
    Dim x As Integer, y As Integer, z As String
    Dim IE As InternetExplorer
    Dim aEle As HTMLLinkElement
    Dim findtext As String, player As String
     
    x = 2

    Set IE = New InternetExplorer
    IE.Visible = True

    Do Until Cells(x, 1) = ""
        'If Left(Cells(x, 4), 2) <> "GB" Then
        '    Cells(x, 4) = "GB" & Replace(Cells(x, 4), " ", "")
        'End If

        IE.Navigate "https://www.tax.service.gov.uk/check-vat-number/enter-vat-details"
        Do While IE.Busy = True Or IE.ReadyState <> 4: DoEvents: Loop
        Application.Wait Now + #12:00:01 AM#

        IE.Document.getElementById("target").Value = Cells(x, 4).Value
        IE.Document.getElementsByName("button.govuk-button")(0).Click
        
        Do While IE.Busy Or IE.ReadyState <> 4: DoEvents: Loop
        Application.Wait Now + #12:00:01 AM#

        y = 2

        For Each aEle In IE.Document.getElementsByClassName("VAT registration details")
            Debug.Print aEle.innerText
             
            z = Trim(aEle.innerText)
            Cells(x, 7) = z

            If Left(z, 1) = "V" Then
                Cells(x, 7).Font.Color = vbBlack
            Else
                Cells(x, 7).Font.Color = vbRed
            End If
             
            With Cells(x, 6)
                .Value = Date
                .NumberFormat = "dd/mm/yyyy"
            End With
             
            y = y + 1
        Next
        x = x + 1
    Loop

End Sub
question from:https://stackoverflow.com/questions/65600002/using-vba-to-extract-information-from-internet-explorer-im-stuck

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...