Copy html table with dropdown menu into excel vba

Reis

New Member
Joined
Feb 18, 2025
Messages
1
Office Version
  1. 2024
Platform
  1. Windows
Good morning to all. Let's see if someone can help me out with this, cause it is making me crazy. I´ve been looking all over to try to make this work on Excel and still can´t make it happen. I have a webpage, with a dropdown menu for selection, and then it presents a table that i want to copy to excel using VBA.

Webpage: Cotações BPI

In here, i find 4 options:

  • Câmbios
  • Fundos de Investimento
  • PPR
  • Seguros de Capitalização
I Want to select the second one "Fundos de Investimento", wait for IE to load the page and then fill the cells on an excel page.
After, need to select third option "PPR", wait for IE to load the page and then fill the cells on another excel page.

Managed to get something, nut now the problem is that the page doesn't update with selection on drop-down menu.

My code:

Sub demo()
Dim IE
Dim ro As Integer
Dim Table As Object
Dim trows As Object
Dim r As Object
Dim tcells As Object
Dim c As Object
Dim objIE As Object
Dim Title As Object


Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "Cotações BPI"

Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop

Set Title = IE.Document.getElementById("wt2_LT_SitePublico_wt151_block_wtContent_wtContent_CW_SP_Fragments_wt3_block_LT_SitePublico_wt10_block_wtLeftContent_LT_SitePublico_Patterns_wt165_block_wtForm_LT_SitePublico_Patterns_wt51_block_wtRow_LT_SitePublico_Patterns_wt228_block_wtInput_wtSelAcoes")
Title.selectedIndex = 1

Application.Wait DateAdd("s", 1, Now)

Set Table = IE.Document.getElementsByTagName("table")
Set trows = Table(0).getElementsByTagName("tr")

ro = 1
For Each r In trows
Set tcells = r.getElementsByTagName("td")
For Each c In tcells

Debug.Print (c.innerText)

ro = ro + 1
Next
Next

End Sub
 

Forum statistics

Threads
1,226,771
Messages
6,192,918
Members
453,766
Latest member
Gskier

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