I am trying to convert a working version of VBA code to VBS but I am encountering many errors.
Like I said, I receive many errors when trying to run that code as VBS, I can list them if necessary.
Any help would be most welcomed.
VBA Code:
Dim lngRecords
Dim StockNumber
'
Dim rngOutput
'
Dim MainURL
Dim strHTML
'
Dim ScrapedValuesArray
Dim StockSymbolArray
'
' Number of output columns
ReDim ScrapedValuesArray(1)
'
' Instantiate MSXML2
Set Doc = New HTMLDocument
'
' Setup variables
MainURL = "https://finance.yahoo.com/quote/"
'
' Get RecordCount
With shtData.Range(Stock_RangeAddr)
lngRecords = .End(xlDown).Row - 1
StockSymbolArray = .Resize(lngRecords)
End With
'
OutputColumnNumber = Range(Stock_RangeAddr).Offset(, 1).Column
'
On Error GoTo ResumeFromHere
'
' Start scraping
For StockNumber = 1 To UBound(StockSymbolArray)
'
DoEvents
Set rngOutput = Range(Stock_RangeAddr).Offset(StockNumber - 1, 1)
'
' Start at first empty output cell
If Len(rngOutput) = 0 Then
'
' Set semaphore
rngOutput = "... Scraping Data ..."
'
' Navigate to property page
strHTML = GetHTML(MainURL & StockSymbolArray(StockNumber, 1))
'
Doc.body.innerhtml = strHTML
'
' Scrape Desired Values from stock page
ScrapedValuesArray(0) = Doc.getElementsByTagName("td")(11).innerText
ScrapedValuesArray(1) = Doc.getElementsByTagName("td")(31).innerText
'
' Print scraped stock values into Excel cells
rngOutput.Resize(, UBound(ScrapedValuesArray) + 1) = ScrapedValuesArray
'
[recordsprocessed] = [recordsprocessed] + 1
'
If [StopGo] = "Stop" Then
Exit For
End If
End If
'
ResumeFromHere:
'
Next
'
' Terminate objects
Set rngOutput = Nothing
Set Doc = Nothing
'
Like I said, I receive many errors when trying to run that code as VBS, I can list them if necessary.
Any help would be most welcomed.