Need some help with VBA to VBS code conversion please

johnnyL

Well-known Member
Joined
Nov 7, 2011
Messages
4,546
Office Version
  1. 2007
Platform
  1. Windows
I am trying to convert a working version of VBA code to VBS but I am encountering many errors. :(

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.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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