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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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