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:
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
Webpage: Cotações BPI
In here, i find 4 options:
- Câmbios
- Fundos de Investimento
- PPR
- Seguros de Capitalização
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