VBA - Internet Explorer - code not working

neilsolaris

New Member
Joined
Feb 5, 2015
Messages
7
Hello,

I wrote some VBA code a a while ago, which checks which VAT registered musicians on my database, if any, have deregistered. Unfortunately I used a European VAT checking website before, and because I'm based in the UK and since we've left the EU recently, it no longer works. Therefore, I have changed it to VAT checking website to a British one. However, I'm getting stuck with some coding. On the first page, I need to enter the VAT number from my Excel file to the search box, and then submit it. Both these lines are not working yet. Is someone able to help show me what I'm doing wrong? Many thanks for your help.

I haven't updated the second part of my code yet (i.e. the next page where it shows if they are VAT registered or not). I'm sure I'll need some help with that too, but I'll see if I can solve the first part first.





Sub CheckVatPlayers()


Dim x As Integer, y As Integer, z As String, objIE As InternetExplorer, aEle As HTMLLinkElement, findtext As String, player As String


x = 2

Set objIE = New InternetExplorer

objIE.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


objIE.Navigate "https://www.tax.service.gov.uk/check-vat-number/enter-vat-details"


Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop

Application.Wait Now + #12:00:01 AM#


objIE.Document.getElementsById("target").Value = Cells(x, 4)

objIE.Document.getElementsById("target")(0).Click



Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop

Application.Wait Now + #12:00:01 AM#

y = 2


For Each aEle In objIE.Document.getElementsByClassName("vat_number_h1")

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
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I'm not sure how to edit the post above, but I changed the line "getElementsbyId" to "getElementbyId". It still doesn't work though!
 
Upvote 0
I'm making a bit of progress now. I've changed this above line to objIE.Document.getElementById("target").Value = Cells(x, 4) and that seems to work.

I'm not sure what the ID is for the submit button though. Therefore, I'm not sure how to make the next line work...

objIE.Document.getElementById("???").Click
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top