VBA - Redeem the value of a website variable

Asked

Viewed 27 times

0

Good evening, everyone!

I’m starting in VBA and I made a macro that returns the information of a pro Excel site, but I’m adjusting some things and I came across a problem a few days ago and I can’t solve:

For the purpose of my project, I am setting all the tables ("tr) of the site:

Set tabela = ie.document.all.tags("tr")

And when I inspect the table variable it returns me a long variable:

inserir a descrição da imagem aqui

I’m trying to copy this value "12" to a VBA variable and then to an Excel cell, but not even the first step I’m getting.

Could you help me please?

Thank you!

1 answer

0

Hi, Jorge.

I couldn’t take the test on your app because it’s pretty vague.

But if you want to get the amount of table line tags "" from an HTML code the easiest way is to use . Getelementsbytagname("tr")

The ready-to-use variable in the cell here in the example is ntr You could set for example: Sheets("Your Spreadsheet"). Range("A1"). Value = ntr

Sub teste()
Dim IE As Object
Dim doc As Object
Dim colTR As Object
Dim colTD As Object
Dim tr As Object
Dim td As Object]

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
IE.Navigate "https://www.w3schools.com/tags/tag_tr.asp"

'wait for page to load
Do Until IE.ReadyState = 4: DoEvents: Loop

Set doc = IE.Document
Set colTR = doc.GetElementsByTagName("tr")

For Each tr In colTR
    nTR = nTR + 1
Next tr

IE.Quit

'Resultado
MsgBox nTR

End Sub

Browser other questions tagged

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