"Excel VBA web scraping" Code Answer's
You're definitely familiar with the best coding language VBA that developers use to develop their projects and they get all their queries like "Excel VBA web scraping" answered properly. Developers are finding an appropriate answer about Excel VBA web scraping related to the VBA coding language. By visiting this online portal developers get answers concerning VBA codes question like Excel VBA web scraping. Enter your desired code related query in the search bar and get every piece of information about VBA code related question on Excel VBA web scraping.
Excel VBA web scraping
Option Explicit
Public Sub GetRates()
Dim html As HTMLDocument, hTable As HTMLTable '<== Tools > References > Microsoft HTML Object Library
Set html = New HTMLDocument
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "https://uk.investing.com/rates-bonds/financial-futures", False
.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" 'to deal with potential caching
.send
html.body.innerHTML = .responseText
End With
Application.ScreenUpdating = False
Set hTable = html.getElementById("cr1")
WriteTable hTable, 1, ThisWorkbook.Worksheets("Sheet1")
Application.ScreenUpdating = True
End Sub
Public Sub WriteTable(ByVal hTable As HTMLTable, Optional ByVal startRow As Long = 1, Optional ByVal ws As Worksheet)
Dim tSection As Object, tRow As Object, tCell As Object, tr As Object, td As Object, r As Long, C As Long, tBody As Object
r = startRow: If ws Is Nothing Then Set ws = ActiveSheet
With ws
Dim headers As Object, header As Object, columnCounter As Long
Set headers = hTable.getElementsByTagName("th")
For Each header In headers
columnCounter = columnCounter + 1
Select Case columnCounter
Case 2
.Cells(startRow, 1) = header.innerText
Case 8
.Cells(startRow, 2) = header.innerText
End Select
Next header
startRow = startRow + 1
Set tBody = hTable.getElementsByTagName("tbody")
For Each tSection In tBody
Set tRow = tSection.getElementsByTagName("tr")
For Each tr In tRow
r = r + 1
Set tCell = tr.getElementsByTagName("td")
C = 1
For Each td In tCell
Select Case C
Case 2
.Cells(r, 1).Value = td.innerText
Case 8
.Cells(r, 2).Value = td.innerText
End Select
C = C + 1
Next td
Next tr
Next tSection
End With
End Sub
Source: stackoverflow.com
All those coders who are working on the VBA based application and are stuck on Excel VBA web scraping can get a collection of related answers to their query. Programmers need to enter their query on Excel VBA web scraping related to VBA code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about Excel VBA web scraping for the programmers working on VBA code while coding their module. Coders are also allowed to rectify already present answers of Excel VBA web scraping while working on the VBA language code. Developers can add up suggestions if they deem fit any other answer relating to "Excel VBA web scraping". Visit this developer's friendly online web community, CodeProZone, and get your queries like Excel VBA web scraping resolved professionally and stay updated to the latest VBA updates.